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

如此本地服务就搭好了。
网友评论