I am working with nodejs and using expressjs framework,Right now i am trying to run "Rest Api"
but i am getting following error
Cannot GET /published
Here is my routes file
module.exports = app => {
const tutorials = require("../controllers/tutorial.controller.js");
var router = require("express").Router();
router.get("/published", tutorials.findAllPublished);
};
Here is my controller
exports.findAllPublished = (req, res) => {
res.send('Hello world');
};
>Solution :
You need to use the router somewhere in your app: app.use('/', router)
This:
module.exports = app => {
const tutorials = require("../controllers/tutorial.controller.js")
var router = require("express").Router()
router.get("/published", tutorials.findAllPublished)
app.use('/', router) // e.g here
}
Should work.