热门搜索 :
考研考公
您的当前位置:首页正文

mac 环境下安装node.js

来源:东饰资讯网

1、下载node.js for mac

下载完成之后,双击安装,一路next,很简单。

2、测试是否安装成功

control + space 键打开spotlight,输入“终端”,在终端做如下操作:

  • 输入 node -v,回车;
  • 输入 npm -v,回车;
    若安装成功的话,则显示版本号

3、测试运行

在(Finder > ~username )目录,新建 helloworld.js,若在Finder左侧栏看不到你的用户名,则打开Finder的偏好设置,勾选你的用户名即可。

编辑helloworld.js编辑以下内容:

var http = require('http');
http.createServer(function(req, res){
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(8808, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8808');

运行:打开“终端”,输入“node helloworld.js”


Top