1.npm install apidoc -g
2.apidoc -i ./ -o ./aaa
apidoc -i 后是编译哪一个文件目录 ./是当前文件 -o 后是编译到哪个目录下 aaa目录下
3.在根目录下创建一个apidoc.json
注意一些版本的apidoc中forceLanage得设置为zh_cn 而不是zh-cn
{
"name": "测试",
"version": "0.0.1",
"description": "API文档测试",
"title": "API文档测试",
"url" : "http://xxxxxxx",
"sampleUrl" : "http://xxxxxxxx",
"template":{
"forceLanguage":"zh_cn"
}
}
4.在写好的api接口上面写上注释就好,
然后在执行第二步的命令
/**
* @api {post} /user/login 用户登录
* @apiName login
* @apiGroup user
* @apiParam {String} us 用户名
* @apiParam {String} ps 用户密码
*
*/
router.post('/login',(req,res)=>{
let {us,ps} = req.body
if(!us||!ps){ return res.send({code:-1,msg:'参数错误'})}
//{us:us,ps:ps}==={us,ps}
User.find({us,ps}).then((data)=>{
console.log(data)
if(data.length>0){
res.send({code:200,msg:'登陆成功'})
}else{
res.send({code:-1,msg:'用户名或密码不正确'})
}
}).catch((err)=>{
res.send({code:-1,msg:'内部错误'})
})
})
效果图