---
title: "[node.js] 解决sublime console中乱码的问题 "
author: "cute.spring"
date: "2014-09-20T13:39:28Z"
tags: []
categories: ["编程语言"]
slug: "node-js-sublime-console"
draft: false
lastmod: "2014-09-20T13:39:28Z"
id: 2118474
url: "https://cute-spring.iteye.com/blog/2118474"
---

插件地址：https://github.com/tanepiper/SublimeText-Nodejs

1. 通过Package Control : Install package 安装Nodejs插件

2. 安装成功后，Tools->Build Systems下会增加一项Nodejs

3. 选中Tools -> Build Systems -> Nodejs

4. 创建一个js文件并保存，内容如下
    console.log("Hello Node.js");

5. Ctrl + b 运行此JS文件

6. 加入中文中文console.log("你好 Node.js")，再 Ctrl + b,结构如下

```js
hello Node.js æˆ‘çš„ 
```


7. Preferences-> Browser Packages
在Sublime\Data\Packages\Nodejs目录下找到Nodejs.sublime-build
改其中的encoding为utf-8即可, 默认为cp1252

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