美文网首页
node框架express搭建本地服务器

node框架express搭建本地服务器

作者: 梦想成真213 | 来源:发表于2017-09-26 10:44 被阅读0次

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

如此本地服务就搭好了。

相关文章

网友评论

      本文标题:node框架express搭建本地服务器

      本文链接:https://www.haomeiwen.com/subject/vesxxxtx.html