Node.js 項目創(chuàng)建
- 新建文件夾myapp
- 在你項目的根目錄下創(chuàng)建一個叫 server.js 的文件,并寫入以下代碼:
var http = require('http');
http.createServer(function (request, response) {
// 發(fā)送 HTTP 頭部
// HTTP 狀態(tài)值: 200 : OK
// 內(nèi)容類型: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// 發(fā)送響應(yīng)數(shù)據(jù) "Hello World"
response.end('Hello World\n');
}).listen(3000);
// 終端打印如下信息
console.log('Server running at http://localhost:3000');
使用Express 應(yīng)用生成器創(chuàng)建項目
http://www.expressjs.com.cn/starter/generator.html
- 安裝生成器 npm install express-generator -g
- express myapp(項目名稱)
- cd myapp
- npm install
- set DEBUG=myapp & npm start 或者直接運行npm start
- 在瀏覽器中打開 http://localhost:3000/ 網(wǎng)址就可以看到這個應(yīng)用了
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。