mac下Sublime Text3配置 NodeJs环境

众所周知,Sublime Text3是一款神器,最近开始接触nodejs,这里记录下nodejs插件的配置

Install

安装就比较简单了,一句话

git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Nodejs

Config

这里有需要修改如下配置文件

Nodejs.sublime-settings

首先通过命令查看mac下node和npm安装位置

which node npm
// 输出如下
/usr/local/bin/node
/usr/local/bin/npm

前往 ~/Library/Application Support/Sublime Text 3/Packages/Nodejs 文件夹查看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
}

Example

新建example.js文件,写入

var http = require('http');

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/ .

注意:sublime text3 编译的文件如果有目录,目录中不要使用空格