nodejs—router 客官°小女子只卖身不卖艺 2022-06-02 10:17 136阅读 0赞 05\_pool\_1.js /** * Created by web-01 on 2018/1/10. */ const mysql=require("mysql"); var pool=mysql.createPool({ host:"127.0.0.1", user:"root", password:"", database:"test", port:3306, connectionLimit:25 }); module.exports=pool; 02\_users\_1.js /** * Created by web-01 on 2018/1/10. */ const express=require("express"); const pool=require("./05_pool_1"); var router=express.Router(); router.get("/list",(req,res)=>{ pool.getConnection((err,conn)=>{ if(err) throw err; var sql="SELECT * FROM t_user"; conn.query(sql,(err,result)=>{ if(err) throw err; res.json(result); conn.release(); }); }); }); router.get("/del",(req,res)=>{ res.json({code:1,msg:"user_del"}) }); router.get("/update",(req,res)=>{ res.json({code:1,msg:"user_update"}) }); module.exports=router; 03\_product\_1.js /** * Created by web-01 on 2018/1/10. */ const express=require("express"); const pool=require("./05_pool_1"); var router=express.Router(); router.get("/list",(req,res)=>{ pool.getConnection((err,conn)=>{ if(err) throw err; var sql="SELECT * FROM t_user"; conn.query(sql,(err,result)=>{ if(err) throw err; res.json(result); conn.release(); }); }); }); router.get("/del",(req,res)=>{ res.json({code:1,msg:"user_del"}) }); router.get("/update",(req,res)=>{ res.json({code:1,msg:"user_update"}) }); module.exports=router; 04\_app.js /** * Created by web-01 on 2018/1/10. */ const http=require("http"); const express=require("express"); const routerUsers=require("./02_users_1"); const routerProduct=require("./03_product_1"); var app=express(); var server=http.createServer(app); server.listen(3001); app.use("/users",routerUsers); app.use("/product",routerProduct);
还没有评论,来说两句吧...