1)安装NodeJS
在官网(https://nodejs.org/en/)下载pkg包,我下载的版本为6.9.5,大小为15.5M。下载的安装包双击下一步安装即可。
可以在终端中查看是否成功安装nodejs
这样我们就安装好了node和npm工具,可以使用它们进行工作了。
2)安装Sublime
3)配置sublime for nodejs
为sublime text下载nodejs插件(下载地址:https://github.com/tanepiper/SublimeText-Nodejs)
解压下载的zip文件并将文件夹命名为Nodejs
复制Nodejs文件夹到sublime的Preferences-Package文件夹中
修改Nodejs.sublime-build和Nodejs.sublime-settings
修改后的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": "/usr/local/bin/node",
- // Same for NPM command
- "npm_command": "/usr/local/bin/npm",
- // as 'NODE_PATH' environment variable for node runtime
- "node_path": false,
- "expert_mode": false,
- "ouput_to_new_tab": false
- }
- {
- "cmd": ["node", "$file"],
- "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
- "selector": "source.js",
- "shell":true,
- "encoding": "cp1252",
- "windows":
- {
- "cmd": ["taskkill /F /IM node.exe & node $file"]
- },
- "linux":
- {
- "cmd": ["killall node; node $file"]
- },
- "osx":
- {
- "cmd": ["/usr/local/bin/node; node $file"]
- }
- }
再重启sublime,选中Tool-build System-Nodejs
编辑Nodejs文件,并保存为后缀为js的文件(如果不保存为.js文件,sublime是无法显示运行结果的)
这样我们就可以通过Tool-Nodejs-Run来运行Nodejs代码了。