xg-server
v1.2.4
Published
这是一个基于express的接口web服务器,可以快速构建一web接口开发服务器
Downloads
379
Readme
基于Express 快速构建web服务器
安装 使用管理员打开终端、cmd
npm i xg-server -g
使用
xg-server create my-app
cd my-app
npm install
启动项目
# 不写端口号,默认是3000
npm run start 端口号
开发目录说明
- api 目录用于快速开发接口 要开发接口,只需要创建一个文件夹/index.js即可 例如 要开发一个/user/login 接口
- 在api目录下新建user文件夹,并创建index.js
/api/user/index.js
const express = require('express');
const router = express.Router();
// 注册接口
router.post('/login',(req,res)=>{
// 所有的中间件都挂载到了 req 和 res上
req.query // 接受 get参数
req.body // 接受 post 参数
req.cookies // cookies
req.session // session
req.db // 数据库连接单例,mysql单例
res.cookie // 设置cookie
})
module.exports = router;