macOS下搭建Node.js环境
2017-02-14 21:08
323 查看
1.安装Homebrew
$:ruby -e "$(curl -fsSl http://raw.githubusercontent.com/Homebred/install/master/install);"[/code]2.安装Node
$:brew install node需要稍微等待一会,看到如下界面即安装成功
3.查看Node版本:
$:node -v测试:
在桌面新建一个test.js的文件
$:cd Desktop/ $:touch test.js $:vim test.js写入以下代码
var http = require('http') var data = {name:'stevin',location:'Beijing'}; var srv = http.createServer(function(req,res) { res.writeHead(200,{'Content-Type':'application/json'}); res.end(JSON.stringify(data)); }); srv.listen(8080,function(){ console.log('listening on localhost:8080'); });编写完后保存并且退出
:wq编辑状态, 然后执行$:node Desktop/test.js运行,显示:listening on localhost:8080第一次系统会询问是否同意接入网络, 点击同意即可,然后在浏览器地址栏键入:localhost:8080, 即可显示数据
{"name":"stevin","location":"Beijing"}
ctrl+c结束运行
相关文章推荐
- [macOS] 搭建 Node.js 开发环境
- Node.JS进行简单新技术分析及环境搭建
- node.js+redis环境搭建
- Windows下Node.js开发环境搭建
- Node.js【2】开发环境搭建(Windows、Linux&Mac)
- Node.js IDE 非联网 相关环境搭建
- node.js环境搭建以及入门级hello程序
- 搭建Node.js开发IDE环境WebStrom5 多图
- Node.JS环境搭建手顺(无脑操作)
- node.js环境搭建&npm配置(win7)
- linux上安装node.js ,npm,与karma--angularJS环境搭建
- Node.js学习之IDE环境搭建
- 搭建Node.js开发IDE环境WebStrom5 多图
- nodejs+express开发环境快速搭建
- 搭建Node.js开发IDE环境WebStrom5
- node.js+redis环境搭建
- Node.js 开发环境搭建及设置
- Node.js学习笔记1:windows环境搭建
- node.js 环境搭建
- Node.js环境搭建