当前位置:   article > 正文

sublime Text 配置Node.js_sublimetext node.js

sublimetext node.js

sublime Text 配置Node.js

第一步:下载安装文件

https://nodejs.org/en/download/

第二步:安装Node.js

双击安装程序,开始安装,安装完成后,在控制台输入 :```node -v```
打印出版本号说明安装成功。
配置环境变量:我的电脑-->属性-->高级设置-->环境变量:
把 D:\Program Files\nodejs 配置到 Path环境变量。
  • 1
  • 2
  • 3
  • 4

第三步:下载sublime Text

http://www.sublimetext.com/

第四步:下载Node.js插件

https://github.com/tanepiper/SublimeText-Nodejs
1、解压后,重命名为:Nodejs
2、把Nodejs复制到sublime Text 的 packages目录下
3、重启sublime Text
4、打开sublime Text --> Tools --> Bulid System --> nodejs
打开 Nodejs.sublime-settings, node_command 和 npm_command 分别配置成安装node的exe文件的绝对路径

  // 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 Files\\nodejs\\node.exe",
  // Same for NPM command
  "npm_command": "D:\\Program Files\\nodejs\\npm.cmd",
  // as 'NODE_PATH' environment variable for node runtime
  "node_path": false,

  "expert_mode": false,

  "output_to_new_tab": false
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

打开Nodejs.sublime-build 修改编码:

 "cmd": ["node", "$file"],
 "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
 "selector": "source.js",
 "shell": true,
 "encoding": "GB2312",
 "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"
   }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

第五步:编写Hello World !

新建Hello World.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/');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

编译 crtl + B
控制台输出:
在这里插入图片描述
浏览器输入:http://127.0.0.1:3000/
在这里插入图片描述

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号