Node.js Express + MongoDB 实现增删查改接口(CRUD)以及登录/注册获取Token API
Express + MongonDB 实现RESTFUL风格基本增删查改已经登陆注册获取Token接口
.env文件里MONGODB_URL
为mongodb数据库地址,testmongo
为数据库名, PORT
为服务端端口默认为3000
- 实现对数据的基本增删改查
- 实现用户的登陆注册获取
token
仓库地址
https://github.com/yuanchao614/Mongodb-Express-CRUD
setUp
git clone
cd Mongodb-Express-CRUD
npm install
npm run dev
Example API
- query all data
不带分页参数默认查询所有数据
header: token
methods: GET
URL: http://localhost:3000/api/v1/user/?pageSize=10&pageIndex=0
Return results:
{
data: [],
total: number,
msg: ''
}
- query by id
header: token
methods: GET
URL: http://localhost:3000/api/v1/user/<id>
Return results: []
- create one
header: token
methods: POST
URL: http://localhost:3000/api/v1/user/
bodyParam:
{
userName: 'admin',
passWord: 'admin'
email: 'admin@qq.com'
}
Return results:
{
data: {},
msg: ''
}
- update one
header: token
methods: POST
URL: http://localhost:3000/api/v1/user/<id>
params: id
bodyParam:
{
userName: 'admin',
passWord: 'admin'
email: 'admin@qq.com'
}
Return results:
{
data: '',
msg: ''
}
- delete one
header: token
methods: DELETE
URL: http://localhost:3000/api/v1/user/<id>
params: id
Return results: {}
- signup
methods: POST
URL: http://localhost:3000/api/v1/auth/signup
body: {
userName,
email,
passWord
}
Return results:
{
token,
data: {},
msg: ''
}
- login
methods: POST
URL: http://localhost:3000/api/v1/auth/login
body: {
email,
passWord
}
Return results: {
token,
data: {},
msg: ''
}
- query by userData count by createDate
header: token
methods: GET
URL: http://localhost:3000/api/v1/user/query/querybyDate
Return results: {
data: [],
msg: ''
}
插件
- mongodb插件
mongoose
https://www.npmjs.com/package/mongoose
bcryptjs
加密插件
jsonwebtoken
生成token插件
nodemon
自动更新插件
morgan
api日志插件
每一个人心中都有一团火,路过的人只看到烟!