node框架express搭建本地服務器

1.首先要有node環境

2.npm init ?初始化package.json


3.全局安裝express,

npm install -g express

進到目錄下:

npm install express --save

4.新建一個server.js 服務,一個html頁面:map-test.html

const path = require('path');

const express = require('express');

const app = express();

app.get('/',function(req,res){

res.sendFile(path.join(__dirname,'map-test.html'));

});

app.get('/list/list.html',function(req,res){

res.sendFile(path.join(__dirname,'/list/list.html'));

});

app.listen("8888",'localhost',function(err){

if(err){

console.log(err);

return;

}

console.log('Listening at http://localhost:8888');

});

5.npm start 開啟本地服務


訪問http://localhost:8888/


點來接去到list.html


如此本地服務就搭好了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容