赞
踩
第一步:安装sublime text3
第二步:安装nodejs在sublime的插件
一。获取nodejs插件SublimeText-Nodejs的方式有2种
- GIT方法
可直接输入 git clone https://github.com/tanepiper/SublimeText-Nodejs "D:\ProgramFiles\Sublime Text 3\Data\Packages\nodejs"
注意下载地址为你的Sublime Text 3相对地址下
- github上直接下载压缩包
地址:https://github.com/tanepiper/SublimeText-Nodejs
下载后解压到sublime text的package目录中。查看package目录可通过菜单栏的Preferences-->浏览程序包
Browse Packages直接打开package目录。
二。修改相应值:
修改编译选项,在package目录下的nodejs目录中,打开Nodejs.sublime-build,
有2个地方需要修改,一个是编码,为了避免乱码code,需要改成cp936;另外一个是cmd命令,本身如果只是想简单的运行nodejs程序的话,windows下面的cmd可以直接
"cmd": ["node", "$file"],但是这样非常不利于开发环境,因为这样的话每次build都会重新启动一个node.exe进程,且会占用一个端口,这肯定是我们不希望的。上文中的cmd原本是想在启动node.exe之前讲node.exe进程都杀掉,然后再启动node.exe,但是这个命令写的不对,直接使用的话是编译不成功的。
对比修改前后的代码将红色部分改为绿色部分
修改前的文档:
修改后的文档
{ "cmd": ["node", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.js", "shell":true, "encoding": "cp1252", "windows": { <span style="color:#CC0000;"><strong>"cmd": ["taskkill /F /IM node.exe & node", "$file"]</strong></span> }, "linux": { "cmd": ["killall node; node", "$file"] } }
配置完成重启sublime text
{ "cmd": ["node", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.js", "shell":true, "encoding": "cp936", "windows": { <span style="color:#006600;"><strong>"cmd": ["taskkill","/F", "/IM", "node.exe","&","node", "$file"] </strong></span> }, "linux": { "cmd": ["killall node; node", "$file"] } }
第三步:测试nodejs程序
在sublime新建一个js文档,输入以下的代码
var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8888); console.log("Server running at http://127.0.0.1:8888/");
Ctrl+b编译这段代码之后,sublime text窗口中就会显示Server running at http://127.0.0.1:8888/
到此,服务端算是启动成功,打开浏览器,输入http://127.0.0.1:8888/,页面显示
Hello World
则表示交互正常。
参考地址:http://www.cnblogs.com/bluesky4485/p/3928364.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。