sublime text 安装nodejs开发插件

系统:windows10
nodejs版本:v6.1.14

请先配置好环境变量,这里就不说啦。

下载并设置nodejs插件

下载地址为https://github.com/tanepiper/SublimeText-Nodejs

下载zip压缩包后解压,文件名改为Nodejs

打开Sublime Text3,点击菜单“Perferences” =>“Browse Packages”打开“Packages”文件夹,并将上一步的Nodejs文件夹剪切进来

 

修改配置文件 (这里有两处文件要修改)

Nodejs.sublime-settings

在 Sublie Text 3 Packages 文件目录下, 找到 Nodejs.sublime-settings (也就是刚才解压的Nodejs目录下)文件,

将代码"node_command": false改为 "node_command": "K:Program Files odejs ode.exe",将代码"npm_command": false改为"npm_command": "K:Program Files odejs pm.cmd",保存文件更改以下内容

修改后的文件为
{
  // save before running commands
  "save_first": true,
  // if present, use this command instead of plain "node"
  // e.g. "/usr/bin/node" or "C:in
ode.exe"
  "node_command": "K:Program Files
odejs
ode.exe",//请对应修改自己的路径
  // Same for NPM command
  "npm_command": "K:Program Files
odejs
pm.cmd",//请对应修改自己的路径
  // as 'NODE_PATH' environment variable for node runtime
  "node_path": false,

  "expert_mode": false,

  "ouput_to_new_tab": false
}

注: 修改了两个地方,分别是 node_command 和 npm_command

Nodejs.sublime-build

同样 找到 Nodejs.sublime-build 文件,将代码 "encoding": "cp1252" 改为 "encoding": "utf8"既可。

修改后的文件为
{
  "cmd": ["node", "$file"],
  "file_regex": "^[ ]*File "(...*?)", line ([0-9]*)",
  "selector": "source.js",
  "shell": true,
  "encoding": "utf8",
  "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"
    }
}

注: 这里只改了一个地方,是 encoding ,windows 下的cmd命令是每次执行的时候都会kill 掉以前启动的nodejs 进程,这个命令网上说有些错误,可能是版本问题,这里shell_cmd不用改既可到达我们想要的效果

测试

新建一个 test.js 文件 输入以前内容,按"ctrl+B"运行代码,运行结果如下所示

或者我们再改下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
');
 
}).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 Text 安装 Node js 步骤 。
参考: https://packagecontrol.io/packages/Nodejs packagecontrol 官网 的Node js 插

原文地址:https://www.cnblogs.com/phpper/p/7712544.html