---
title: "NodeJS Sublime环境配置"
author: "fairy_xzc"
date: "2017-01-10T22:29:20Z"
tags: []
categories: ["Web前端"]
slug: "nodejs-sublime"
draft: false
lastmod: "2017-05-10T15:05:52Z"
id: 2352335
url: "https://agilestyle.iteye.com/blog/2352335"
---

**原创转载请注明出处：[http://agilestyle.iteye.com/blog/2352335](/blog/2352335)**

 

## Prerequisite

![](http://dl2.iteye.com/upload/attachment/0122/5181/15e51af2-cfce-3a60-84db-518180fa7f89.png)  
 

![](http://dl2.iteye.com/upload/attachment/0122/5179/5ea5102a-7717-3312-9978-324e964dc4c6.png)  
 

 

[https://github.com/tanepiper/SublimeText-Nodejs](https://github.com/tanepiper/SublimeText-Nodejs) 下载zip包

![](http://dl2.iteye.com/upload/attachment/0122/5198/8f2f5e6d-5718-38d5-8f00-964383ca693f.png)  
 

解压后，重命名为nodejs，拷贝到

C:\\Users\\Administrator\\AppData\\Roaming\\Sublime Text 2\\Packages

![](http://dl2.iteye.com/upload/attachment/0122/5177/0496abf8-16bf-310d-920c-79e754a2c07f.png)  
 

设定build环境为nodejs

Tools &gt; Build System &gt; Nodejs

![](http://dl2.iteye.com/upload/attachment/0122/5202/b2a0ac93-6406-30f8-ac43-e287ff3b403b.png)  
 

 

配置环境

Preferences &gt; Package Settings &gt; Nodejs &gt; Settings-Default 

![](http://dl2.iteye.com/upload/attachment/0122/5204/cb4cfb96-2a2e-3870-9773-3d5a14858d65.png)  
修改如下： 

```
{
  // 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": "C:/Program Files/nodejs/node.exe",
  // Same for NPM command
  "npm_command": "C:/Program Files/nodejs/npm.cmd",
  // as 'NODE_PATH' environment variable for node runtime
  "node_path": "C:/Users/Administrator/AppData/Roaming/npm/node_modules",

  "expert_mode": true,

  "ouput_to_new_tab": false
}
```

 

新建一个index.js文件，编写一个NodeJS脚本

```
var http = require('http');

http.createServer(function (request, response) {
	response.writeHead(200, {'Content-Type': 'text/plain'});

	response.end('Hello World\n');
}).listen(8888);

console.log('Server running at http://127.0.0.1:8888/');
```

 

Ctrl + B运行

![](http://dl2.iteye.com/upload/attachment/0122/5183/96c637bc-90ea-3a2b-acd5-29db3c7f0d2c.png)  
 

运行成功后，如果想停止服务，可以在Tools &gt; Cancel Build来停止服务

![](http://dl2.iteye.com/upload/attachment/0122/5214/8d6b1f36-8d2a-341f-9ccd-a17a3e09f176.png)  
 

**Sublime作为JS IDE安装几个比较著名的插件**

## JsFormat

[https://github.com/jdc0589/JsFormat](https://github.com/jdc0589/JsFormat)

### Usage

Either cmd+alt+f on OS X or **ctrl+alt+f** on Linux/Windows

 

## JSHint

[https://github.com/uipoet/sublime-jshint](https://github.com/uipoet/sublime-jshint)

### Usage

ctrl+j on OS X or **alt+j** on Linux/Windows

 

## JavaScriptNext

[https://github.com/Benvie/JavaScriptNext.tmLanguage](https://github.com/Benvie/JavaScriptNext.tmLanguage)

### Usage

You can either set individual JavaScript files to use this syntax highlighter by changing it in the “View -&gt; Syntax” menu or you can change it for all JavaScript files in the “**View -&gt; Syntax -&gt; Open all with current extension as...**”.

 

## sublime-marko

[https://github.com/merwan7/sublime-marko](https://github.com/merwan7/sublime-marko%20) 

 

## HTMLPrettify

[https://github.com/victorporof/Sublime-HTMLPrettify](https://github.com/victorporof/Sublime-HTMLPrettify)

 

## emmet-sublime

[https://github.com/sergeche/emmet-sublime](https://github.com/sergeche/emmet-sublime)

note：这个插件安装需要安装PyV8（[https://github.com/emmetio/pyv8-binaries](https://github.com/emmetio/pyv8-binaries)）

emmet初始化html，输入 html:5 ，之后按下 Ctrl + E

![](http://dl2.iteye.com/upload/attachment/0123/8104/49af6ca9-4e92-34de-a5dd-a5a962f34b5f.png)

 

另外可以修改Sublime默认的 编码、字体大小、Tab

Preferences &gt; Settings - User

```
{
	"default_encoding": "UTF-8",
	"font_size": 16,
	"tab_size": 2
}
```