前言前言大家都知道,Sublime Text 安装插件一般从 Package Control 中直接安装即可,当我安装 node js 插件时候,直接通过Package Control 安装,虽然插件安装成功了,但是找不到配置文件 Nodejs.sublime-build 来更改一些配置 。于是去 https://packagecontrol.io/packages/Nodejs 官网上查看,只提供一种安装方式。安装安装git安装MacOSX
git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Nodejs
git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/NodejsWindows
git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Nodejs
git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/NodejsLinux
git clone https://github.com/tanepiper/SublimeText-Nodejs $HOME/.config/sublime-text-3/Packages/Nodejs
git clone https://github.com/tanepiper/SublimeText-Nodejs $HOME/.config/sublime-text-3/Packages/Nodejs手动安装手动安装通过地址https://github.com/tanepiper/SublimeText-Nodejs去github上下载该包,解压放到Sublime Text3\Packages 目录下。https://github.com/tanepiper/SublimeText-Nodejs修改配置文件 (两处要修改)Nodejs.sublime-settingsNodejs.sublime-settings在 Sublie Text 3 Packages 文件目录下, 找到 Nodejs.sublime-settings 文件,更改以下内容修改后的文件
{
// 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": false,

"expert_mode": false,

"ouput_to_new_tab": false
}
{
// 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": false,

"expert_mode": false,

"ouput_to_new_tab": false
}注: 修改了两个地方,分别是 node_command 和 npm_commandNodejs.sublime-buildNodejs.sublime-build在 Sublie Text 3 Packages 文件目录下, 找到 Nodejs.sublime-build 文件,更改以下内容修改后的文件
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "utf8",
"windows":

{


"cmd": ["taskkill","/F", "/IM", "node.exe","&","node", "$file"]

},
"linux":

{

"cmd": ["killall node; node", "$file"]

},

"osx":

{

"cmd": ["killall node; node $file"]

}
}
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "utf8",
"windows":

{


"cmd": ["taskkill","/F", "/IM", "node.exe","&","node", "$file"]

},
"linux":

{

"cmd": ["killall node; node", "$file"]

},

"osx":

{

"cmd": ["killall node; node $file"]

}
}注: 修改了两个地方,分别是 encoding 和 windows 下的cmd ,windows 下的cmd命令是每次执行的时候都会kill 掉以前启动的nodejs 进程,这个命令有些错误,我们修改它,到达我们想要的效果测试测试新建一个 test.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/');
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/');Ctrl +B 编译一下,会在Sublime Text 控制台 看到 Server running at http://127.0.0.1:3000/ ,接下来我们从浏览器打开 访问 http://127.0.0.1:3000/ .Ctrl +B结束语结束语以上就是 Sublime Text 排至 Node js 步骤 。
参考: https://packagecontrol.io/packages/Nodejs packagecontrol 官网 的Node js 插件.https://packagecontrol.io/packages/Nodejs packagecontrolSublime Text3 配置 NodeJs 环境补充Sublime Text3 配置 NodeJs 环境补充一.下载包地址一.下载包地址
https://github.com/tanepiper/SublimeText-Nodejs
https://github.com/tanepiper/SublimeText-Nodejs然后解压放到Sublime Text3\Packages 目录下并改名Nodejs二.修改配置文件 (两处要修改)二.修改配置文件 (两处要修改)1.在 Sublie Text 3 Packages 文件目录下 找到 Nodejs.sublime-settings 文件 更改以下内容 路径为当前电脑node的安装目录
"node_command": "C:\\Program Files\\nodejs\\node.exe",
"npm_command": "C:\\Program Files\\nodejs\\npm.cmd",2.在 Sublie Text 3 Packages 文件目录下 找到 Nodejs.sublime-build 文件
更改以下内容
"encoding": "utf8",
"cmd": ["taskkill","/F", "/IM", "node.exe","&","node", "$file"]三.测试三.测试新建文件夹ss目录下新建test.js文件代码如下
var http = require('http');

http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('hello world\n');
}).listen(1337, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1337/');
var http = require('http');

http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('hello world\n');
}).listen(1337, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1337/');命令行ss目录下运行输入 node test.js安装成功则console.log()