Mac下安装Node.JS
2018-04-19 本文已影响0人
萌咚咚
Step1
访问Node官网并下载(红色框框)

Step2
打开apk并安装

Step3
打开终端输入:
npm -v
node -v

Step4
创建js文件(这里使用Sublime Text):
1.安装Sublime Text
2.下载Sublime Text 的nodejs插件并进行配置
将下载下来的zip包解压,并将名称改为Nodejs
选中Sublime ->perferences->Browse Packages
![]()
将Nodejs文件夹放Packages文件夹中
![]()
在Nodejs文件夹中找到Nodejs.sublime-build和Nodejs.sublime-settings文件进行修改,修改后如下图
setting改后
bulid改后
然后重启Sublime,然后选中Tool->Build System->Nodejs
![]()
3.创建nodejs文件
新建并保存为后缀名.js的文件
![]()
Step 5
在.js文件中输入代码,command + b运行
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {
"Content-Type" : "text/plain"
});
response.write("Welcome to Nodejs");
response.end();
}).listen(8001, "127.0.0.1");
console.log("Creat server on http://127.0.0.1:8001/");

Step 6
打开浏览器输入http://127.0.0.1:8001/
