Answer the question
In order to leave comments, you need to log in
Why doesn't routing work in Express.js through Router?
I can't get the application to work through the Router object in Express.
The structure of the application is as follows (what is relevant to the problem):
index.js
fn.js
/routes/getSettings.js
Code in index.js
const express = require('express');
const getSettingsRouter = require('./routes/getSettings');
const app = express();
app.use('/getSettings', getSettingsRouter);
const express = require('express');
const router = express.Router();
const fn = require('../fn.js');
router.get('/getSettings', async (req, res) => {
let response = await fn.getSettings();
res.type('json');
res.send(response);
});
module.exports = router;
Answer the question
In order to leave comments, you need to log in
It seems to me that it is more correct to replace this in the /routes/getSettings.js file
on thisrouter.get('/', async (req, res) => { /*...*/ })
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question