mac 环境下安装node.js

2016-08-12  本文已影响95人  whbsspu

1、下载node.js for mac

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

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

2、测试是否安装成功

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

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”

上一篇 下一篇

猜你喜欢

热点阅读