本文介绍了JSDocs:记录Node.js快递路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力用JSDocs记录router.get调用.如果我尝试将文档附加到路由器调用本身上,则无法使该文档正确显示在页面上.
I am struggling documenting router.get calls with JSDocs. I am unable to get the documentation to display correctly on the page if I try to append it to my router call itself.
/**
* Health check
* @memberof health
*/
router.get('/happy', function(req, res) {
res.json({ "status" : "OK" });
});
为解决此问题,我使函数具有名称.
To resolve it, I made the functions have names.
router.get('/happy', happy);
/**
* Health check
* @memberof health
*/
function happy(req, res) {
res.json({ "status" : "OK" });
}
这有效,但是我真的很想找到一种方法来使第一种方法起作用.有没有办法记录第一个示例?我可以使用一个关键字吗?
This works, but I would really like to find a way to get the first method to work. Is there a way to document the first example? A keyword I can use?
推荐答案
我在代码中执行以下操作.
I do the following in my code.
/** Express router providing user related routes
* @module routers/users
* @requires express
*/
/**
* express module
* @const
*/
const express = require('express');
/**
* Express router to mount user related functions on.
* @type {object}
* @const
* @namespace usersRouter
*/
const router = express.Router();
/**
* Route serving login form.
* @name get/login
* @function
* @memberof module:routers/users~usersRouter
* @inner
* @param {string} path - Express path
* @param {callback} middleware - Express middleware.
*/
router.get('/login', function(req, res, next) {
res.render('login', {title: 'Login', message: 'You must login'});
});
输出为:
这篇关于JSDocs:记录Node.js快递路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!