S. N
S. N

Reputation: 3959

REST api/postman - Cannot GET /the route Error

I am building a (RESTful) Node.js API, using this tutorial.

I have nade a server.js

const express        = require('express');
const MongoClient    = require('mongodb').MongoClient;
const bodyParser     = require('body-parser');

const app            = express();

const port = 8080;

app.listen(port, () => {
  console.log('We are live on ' + port);
});

I can run my server and see the message :

We are live on 8080

my index.js

const noteRoutes = require('./note_routes');

module.exports = function(app, db) {
  noteRoutes(app, db);
  // Other route groups could go here, in the future
};

and my node_routes.js

//create a node
module.exports = function(app, db) {

    app.post('/notes', (req, res) => {
        // You'll create your note here.
        res.send('Hello')
    });

};

index.js and node_routes.js are both inside app\routes\

I have also downloaded the post man app, to make simple requests

and I get the error

Cannot POST /notes

enter image description here

what am I doing wrong?? I can not figure it out!

Upvotes: 3

Views: 11926

Answers (1)

JazzBrotha
JazzBrotha

Reputation: 1748

There is an error in your server.js

You are missing require('./app/routes')(app, {});

Should be:

require('./app/routes')(app, {});
app.listen(port, () => {
  console.log('We are live on ' + port);
});

Upvotes: 1

Related Questions