Answer the question
In order to leave comments, you need to log in
How to get a list of all routes and methods in Express?
The essence is that, it is necessary to receive all routes of application and methods of these routes.
For example:
File ./app.js
// Подключаем Express
var express = require('express');
var app = express();
// Подключаем файл с маршрутами
require('./routes') (app);
// Файлы маршрутов
var login = require('./login.js')
var users = require('./users.js')
module.exports = function(app) {
app.use('/users,users);
}
var express = require('express');
var router = express.Router();
router.get('/', (req, res) => {
// .... Страница со списком пользователей
})
router.get('/add', (req, res) => {
// .... Добавление пользователей
})
router.post('/add', (req, res) => {
// .... Добавление пользователей
})
Answer the question
In order to leave comments, you need to log in
Maybe someone will come in handy. Using module npmjs.com/package/express-list-endpoints
It outputs my routes for example
[ { path: '/login', methods: [ 'GET' ] },
{ path: '/login', methods: [ 'POST' ] },
...]
app.route
or as in my case (tweak the code a little)router.route
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question