美文网首页
mac 环境下安装node.js

mac 环境下安装node.js

作者: whbsspu | 来源:发表于2016-08-12 15:29 被阅读95次

1、下载node.js for mac

https://nodejs.org/en/download/

下载完成之后,双击安装,一路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”


若无误,则显示 Server running at http://127.0.0.1:8808

打开safari,输入http://127.0.0.1:8808 , 显示“Hello World”

相关文章

网友评论

      本文标题:mac 环境下安装node.js

      本文链接:https://www.haomeiwen.com/subject/omqesttx.html