1. 在package.json 加上request項目
package.json
{
"name": "englistNodeServer",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.2.6",
"jade": "*",
"less-middleware": "*",
"socket.io" : "1.0.6" ,
"request" : "2.39.0"
}
}
2. 打開node.js命令列,進入package.json 同層資料夾下
- npm install
3. 編輯檔案 app.js
var request = require('request');
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Print the google web page.
}
})
4. 啟動app.js
- node app.js
即可看到回覆內容