Thursday, 8 June 2017

Express JS node framework did not respond to post() request

I'm following a blog to build my first node API with express framework. But the POST request did not return a response.

const app = express();

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

module.exports = function(app, db) {
  console.log('reached2');
  app.post('/notes', (req, res) => {
    // You'll create your note here.
    console.log('reached3');
    res.send('Hello');
    //res.end();;
  });
};

Here are my console logs,

reached1
reached2
We are live on 8000

Here are my dependencies,

"dependencies": {
    "body-parser": "^1.17.2",
    "express": "^4.15.3",
    "mongodb": "^2.2.28"
  },
  "devDependencies": {
    "nodemon": "^1.11.0"
  }

Im using the postman client to POST. I tried replacing the fat arrow operator with an anonymous function but still doesnt work.

Please point the problem in this code.



via ProgramCpp

No comments:

Post a Comment