1.安裝node.js
確保mac電腦上已經(jīng)安裝homeBrew,使用下面命令安裝node.js
brew install node
檢測版本
node -v
2.使用node.js開發(fā)web程序
再目錄/User/mac/test下編寫node.js的測試文件test.js,內(nèi)容如下
var http = require('http');
var data = {key:'value',hello:'hello'};
var srv = http.createServer(function(req,res){
res.writeHead(200,{'Content-type':'application/json'});
res.end(JSON.stringify(data));
});
srv.listen(8080,function(){
console.log('listening on localhost:8080');
});
以上代碼將監(jiān)聽8080端口的http請求
3.運行node.js
到/User/mac/test/目錄下啟動node.js,執(zhí)行命令:
node test.js

瀏覽器訪問查看返回
http://localhost:8080/

至此我們已經(jīng)完成了node.js的安裝,下面我們使用intellij來編寫nodeJs程序,需要配置以下插件:
4.intellij集成nodeJs插件
preference-》plugins-》install jetBrains plugins-》輸入node,選擇nodeJs(javaScript)