赞
踩
提示:学习express,搭建管理系统
需求:主要学习express,所以先写service部分
const express = require('express');
const app = express();
const router = express.Router();
const port = 1990;
//初始化路由
require('./routes/index')(router);
app.use('/', router);
app.listen(port,()=>{
console.log('http://localhost:'+port);
})
const userRoutes = require('./user');
const routes = (router)=>{
//user路由
userRoutes(router);
}
module.exports = routes;
这里方便在浏览器测试效果,所以/user/register和/user/login用get请求,后面用Apipost工具的时候,会改成post请求
const userRoutes = (router)=>{
router.get('/user/register',(req,res)=>{
res.send('router register');
});
router.get('/user/login',(req,res)=>{
res.send('router login');
});
}
module.exports = userRoutes;
npm run dev
http://localhost:1990/user/register
http://localhost:1990/user/login
踩坑路漫漫长@~@
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。