1. Create a new blank project
2. Initialize npm
npm init -y
3. Install express
npm install express -s
4.lanbowan_server/Index.js:
Create a new index.js file in the root directory
const express=require('express')
const router=require('./router/router.js')
// 创建服务器
const app=express();
app.use('/',router)
app.listen('7788',()=>{
console.log('服务端启动成功啦。。。。。');
console.log('http://localhost:7788');
})
lanbowan_serve/router/router.js:
const express=require('express')
// 路由
const router=express.Router();
router.get('/test',(req,res)=>{
res.send({
data:'测试成功'
})
})
module.exports=router;
5. Test whether the server is successful
Replenish:
Automatically restart services using nodemon
Global installation
npm install -g nodemon
Development environment installation
npm install --save-dev nodemon
Enter nodemon directly when using