sublime Text 配置Node.js
第一步:下载安装文件
https://nodejs.org/en/download/
第二步:安装Node.js
双击安装程序,开始安装,安装完成后,在控制台输入 :```node -v```
打印出版本号说明安装成功。
配置环境变量:我的电脑-->属性-->高级设置-->环境变量:
把 D:\Program Files\nodejs 配置到 Path环境变量。
第三步:下载sublime Text
http://www.sublimetext.com/
第四步:下载Node.js插件
https://github.com/tanepiper/SublimeText-Nodejs
1、解压后,重命名为:Nodejs
2、把Nodejs复制到sublime Text 的 packages目录下
3、重启sublime Text
4、打开sublime Text --> Tools --> Bulid System --> nodejs
打开 Nodejs.sublime-settings, node_command 和 npm_command 分别配置成安装node的exe文件的绝对路径
// save before running commands
"save_first": true,
// if present, use this command instead of plain "node"
// e.g. "/usr/bin/node" or "C:\bin\node.exe"
"node_command": "D:\\Program Files\\nodejs\\node.exe",
// Same for NPM command
"npm_command": "D:\\Program Files\\nodejs\\npm.cmd",
// as 'NODE_PATH' environment variable for node runtime
"node_path": false,
"expert_mode": false,
"output_to_new_tab": false
}
打开Nodejs.sublime-build 修改编码:
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell": true,
"encoding": "GB2312",
"windows":
{
"shell_cmd": "taskkill /F /IM node.exe & node $file"
},
"linux":
{
"shell_cmd": "killall node; /usr/bin/env node $file"
},
"osx":
{
"shell_cmd": "killall node; /usr/bin/env node $file"
}
}
第五步:编写Hello World !
新建Hello World.js
var http = require('http');
var os = require('os');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://127.0.0.1:3000/');
编译 crtl + B
控制台输出:

浏览器输入:http://127.0.0.1:3000/

本文介绍如何在SublimeText中配置Node.js环境,包括安装Node.js、配置环境变量、下载并安装SublimeText及Node.js插件,以及如何在SublimeText中运行Node.js程序。
366

被折叠的 条评论
为什么被折叠?



