1.下载https://github.com/tanepiper/SublimeText-Nodejs
2.解压到sublime->Preferences->Browse Packages 打开的目录,然后改名nodejs
3.重启sublime,选择Tools->Build System->nodejs
4.打开Preferences->Package Settings->Nodejs->Default配置如下:
{
// 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": "C:\\Program
Files\\nodejs\\node.exe",
// Same for NPM command
"npm_command":
"C:\\Program Files\\nodejs\\npm.cmd",
// as ‘NODE_PATH‘ environment
variable for node runtime
"node_path": "C:\\Program Files\\nodejs",
"expert_mode": false,
"ouput_to_new_tab": false
}
5.打开插件包中的Nodejs.sublime-build配置如下:
{
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\",
line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "GB2312",
"windows":
{
"cmd": ["node",
"$file"]
},
"linux":
{
"cmd": ["killall node;
node", "$file"]
}
}
6 测试 编写如下代码
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(8124);
console.log(‘Server running at http://127.0.0.1:8124/‘);
然后按ctrl+B查看