`

sublime安装node插件

    博客分类:
  • node
 
阅读更多

 

1.下载插件

https://github.com/tanepiper/SublimeText-Nodejs

(通过package-control安装会是过时的版本)

 

2.将插件存放到sublime插件库中

 

3修改Nodejs.sublime-build配置文件

{

  "cmd": ["D:/Program/nodejs/node.exe", "$file"],

  #文件所在路径

  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",

  "selector": "source.js",

  "shell":true,

  "encoding": "cp936",

  "windows":

    {

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

                   #杀死一个node进程,否则每次启动原先的进程还会存在,且占用端口

    },

  "linux":

    {

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

    },

    "osx":

    {

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

    }

}

 

4修改Nodejs.sublime-setting配置文件

{

  // 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": "D:/Program/nodejs/node.exe",

  // Same for NPM command

  "npm_command":"D:/Program/nodejs/npm",

  // as 'NODE_PATH' environment variable for node runtime

  "node_path": false,

 

  "expert_mode": false,

 

  "ouput_to_new_tab": false

 

}

重启完成配置

 

5.检测插件是否安装成功,运行如下js文件,选择运行-编译系统-nodejs,执行ctrl+b命令

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/');

 

弹出Server running at http://127.0.0.1:3000/提示窗即为成功,127.0.0.1即为localhost

 

备注:node为了提高性能,文件加载后第二次读取直接访问内存,因而对文件中代码的改动需要重新关闭再开启node才能成功解析,通过npm install -g supervisor添加supervisor组件,再通过supervisor ***.js命令载入文件可以避免从内存直接读取,进而成功解析修改后的代码段

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics