惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - bluesky4485

Elasticsearch及java客户端jest使用 CentOS6.4安装及配置oracle - bluesky4485 Ant学习 - bluesky4485 Springframework3.1源码编译 如何测试java支持的最大内存 win7x64下安装oraclex64版本后,plsql Developer无法登录的问题 VMWare安装redhat9后上网的的问题 Tomcat中部署后JspFactory报异常的解决方案 - bluesky4485 MyEclipse10 中增加svn插件 Oracle连接池信息的修改 OPDS1.1 VMware下Redhat9鼠标选用usb后不能使用的解决办法 m2e插件安装 Java开发Maven环境配置和介绍 javadoc生成出现错误“编码 GBK 的不可映射字符” - bluesky4485 Google常用搜索技巧 - bluesky4485 设置Google不跳转到google.com.hk CodeSmith支持中文配置 jni和C++通信中文乱码的问题 - bluesky4485
在windows环境下基于sublime text3的node.js开发环境搭建
bluesky4485 · 2014-08-21 · via 博客园 - bluesky4485

首先安装sublime text3,百度一堆,自己找吧。理论上sublime text2应该也可以。我只能说一句:这个软件实在是太强悍了。

跨平台,丰富的插件体系,加上插件基本上就是一个强悍的ide了。目前我在使用的主要是Emmet、Python、还有一些格式化的插件(xml,json),加上这次安装的node.js。

node.js的安装就不用多说了,直接http://nodejs.org/ 点击install下载window版本的安装程序后安装即可。默认的安装会将安装目录加到path环境变量中,这一步是为了后续使用node的时候,可以不用带路径,当然,后续在sublime text中安装好nodejs插件之后,也可以对node的路径进行一些自定义的设置。为了使用方便,建议增加到path环境变量。

SublimeText-Nodejs插件(https://github.com/tanepiper/SublimeText-Nodejs

原本在sublime text的插件库里面有nodejs的插件,但是经过尝试安装后,发现无法修改编译设置,没找到Nodejs.sublime-build文件,后来在github上面看了下人家的安装说明之后再重新安装的。

安装也有二种方式:

1、直接下载压缩包后解压到sublime text的package目录中。查看package目录在哪可以通过菜单栏中的Preferences-->浏览程序包Browse Packages直接打开package目录。

2、使用git命令下载到package目录(git clone https://github.com/tanepiper/SublimeText-Nodejs "D:\ProgramFiles\Sublime Text 3\Data\Packages\nodejs")

修改编译选项,在package目录下的nodejs目录中,打开Nodejs.sublime-build,原始内容如下:

{
  "cmd": ["node", "$file"],
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  "selector": "source.js",
  "shell":true,
  "encoding": "cp1252",
  "windows":
    {
      "cmd": ["taskkill /F /IM node.exe & node", "$file"]
    },
  "linux":
    {
        "cmd": ["killall node; node", "$file"]
    }
}

有2个地方需要修改,一个是编码,为了避免乱码code,需要改成cp936;另外一个是cmd命令,本身如果只是想简单的运行nodejs程序的话,windows下面的cmd可以直接 "cmd": ["node", "$file"],但是这样非常不利于开发环境,因为这样的话每次build都会重新启动一个node.exe进程,且会占用一个端口,这肯定是我们不希望的。上文中的cmd原本是想在启动node.exe之前讲node.exe进程都杀掉,然后再启动node.exe,但是这个命令写的不对,直接使用的话是编译不成功的。对cmd命令需要做简单的处理,修改好之后的Nodejs.sublime-build文件内容如下:

{
  "cmd": ["node", "$file"],
  "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
  "selector": "source.js",
  "shell":true,
  "encoding": "cp936",
  "windows":
    {
        "cmd": ["taskkill","/F", "/IM", "node.exe","&","node", "$file"]  
    },
  "linux":
    {
        "cmd": ["killall node; node", "$file"]
    }
}

重启sublime text之后,配置就算完成了。我们写一小段代码来验证一下是否可以正常运行。

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/');
 
 
Ctrl+b编译这段代码之后,sublime text窗口中就会显示

Server running at http://127.0.0.1:3000/

若之前有运行的node进程在,则会先杀掉node进程,再启动node,显示如下:

成功: 已终止进程 "node.exe",其 PID 为 154588。
Server running at http://127.0.0.1:3000/

到此,服务端算是启动成功,打开浏览器,输入http://127.0.0.1:3000/,页面显示Hello World则表示交互正常。

开发环境就算是基本搭建完毕了,准备接下来一篇文章讲讲怎么使用自带的NPM包管理工具,NPM能解决nodejs代码部署上的很多问题。