sublime Text 配置Node.js

sublime Text 配置Node.js

第一步:下载安装文件

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

第二步:安装Node.js

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

第三步:下载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
}

打开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"
   }
}

第五步:编写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/');

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值