Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot GET error message showing using Rest Api in Nodejs

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading