Sublime Text3 简单开发nodejs

在装好node和sublime Text之后,配置sublime Text3。

一、下载sublime Text的nodejs插件

https://github.com/tanepiper/SublimeText-Nodejs

二、下载后解压

直接改名为nodejs 放到 Preferences–>浏览程序包Browse Packages所在的文件夹

三、修改配置

打开Nodejs文件夹,找到文件“Nodejs.sublime-build”, 拖拽到sublime,显示:

{ 
   "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"] 
    } 
  }

修改为

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

四、完成

随便写一段nodejs代码,ctrl+B运行(附上mysql测试连接)

/**
 * Created by zly on 2015/7/15.
 */

var mysql = require('mysql');

var option = {
    host: 'localhost',
    port: '3306',
    database: 'bi-demo',
    user: 'root',
    password: 'root'
};

var connection = mysql.createConnection(option);
connection.connect(function (err) {
    if (err) {
        console.log("mysql open connection failure");
    } else {
        console.log("mysql open connection success");

        connection.query("select * from feedata", function (err, result) {
            console.log(result);
        });

        connection.end(function (err) {
            if (err) {
                console.log("mysql close connection failure");
            } else {
                console.log("mysql close connection success");
            }
        }); 
    }
})
console.log("hello");

注意:

在手动解压sublime Text插件后,需要在preference->package settings->package control的user setting下添加installed packages中的“Nodejs”,不然重启sublime Text 会被删除Nodejs插件。

{
    "bootstrapped": true,
    "in_process_packages":
    [
    ],
    "installed_packages":
    [
        "Alignment",
        "Colorcoder",
        "ConvertToUTF8",
        "CTags",
        "Git",
        "Github Tools",
        "Nodejs",
        "Package Control",
        "PHPIntel",
        "SFTP",
        "SublimeCodeIntel",
        "Tag",
        "TortoiseSVN",
        "Xdebug Client"
    ]
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mitsuhide1992

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值