標籤:nodejs ram git安裝 git osx nod and www config
來源於:http://www.cnblogs.com/qiaojie/p/5560388.html
前言
大家都知道,Sublime Text 安裝外掛程式一般從 Package Control 中直接安裝即可,當我安裝 node js 外掛程式時候,直接通過Package Control 安裝,雖然外掛程式安裝成功了,但是找不到設定檔 Nodejs.sublime-build 來更改一些配置 。於是去 https://packagecontrol.io/packages/Nodejs 官網上查看,只提供一種安裝方式。
安裝git安裝
MacOSX
git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Nodejs
Windows
git clone https://github.com/tanepiper/SublimeText-Nodejs.git ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Nodejs
Linux
git clone https://github.com/tanepiper/SublimeText-Nodejs $HOME/.config/sublime-text-3/Packages/Nodejs
手動安裝
通過地址https://github.com/tanepiper/SublimeText-Nodejs去github上下載該包,解壓放到Sublime Text3\Packages 目錄下。
修改設定檔 (兩處要修改)Nodejs.sublime-settings
在 Sublime Text 3 Packages 檔案目錄下, 找到 Nodejs.sublime-settings 檔案,更改以下內容
修改後的檔案
{ // 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": "D:\\Program Files\\nodejs\\node.exe" , // Same for NPM command "npm_command": "D:\\Program Files\\nodejs\\npm.cmd", // as ‘NODE_PATH‘ environment variable for node runtime "node_path": false, "expert_mode": false, "ouput_to_new_tab": false}
注: 修改了兩個地方,分別是 node_command 和 npm_command
Nodejs.sublime-build
在 Sublime Text 3 Packages 檔案目錄下, 找到 Nodejs.sublime-build 檔案,更改以下內容
修改後的檔案
{
"cmd": ["node", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.js", "shell":true, "encoding": "utf8", "windows": { "cmd": ["taskkill","/F", "/IM", "node.exe","&","node", "$file"] }, "linux": { "cmd": ["killall node; node", "$file"] }, "osx": { "cmd": ["killall node; node $file"] }}
注: 修改了兩個地方,分別是 encoding 和 windows 下的cmd ,windows 下的cmd命令是每次執行的時候都會kill 掉以前啟動的nodejs 進程,這個命令有些錯誤,我們修改它,到達我們想要的效果
測試
建立一個 test.js 檔案 輸入以前內容
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/ ,接下來我們從瀏覽器開啟 訪問 http://127.0.0.1:3000/ .
Sublime Text3 配置 NodeJs 環境