Q:

when call router.post method from url get error 404 not found in express.js

I have got a problem with Express, I am trying to use the app.post() function but it's not working and I don't know why...
Even though I have included the bodyParser()...
It returns 404 page not found error
var express = require('express');

var MongoClient = require('mongodb').MongoClient;

var router = express.Router();

router.post("/hello",(req, res) => {
        res.send('POST CALL');
    });

/* GET home page. */
router.get('/', function(req, res, next) {
    MongoClient.connect('mongodb://localhost:27017/nicky', function (err, client) {
        if (err) throw err

        var db = client.db('nicky')

        db.collection('student').find().toArray(function (err, result) {
            if (err) throw err
            res.send(JSON.stringify(result));
        })
    })
});
module.exports = router;

GET is working properly, but POST is not.

A:

I am not sure how rest of your code looks, but I have copied your provided snippet and it works this way:
express-post.js:
const express = require('express');
const router = express.Router();

// curl -X POST http://localhost:3000/bar/hello
router.post("/hello",(req, res) => {
    res.send('It is POST');
});

// curl -X GET http://localhost:3000/bar/hi
router.get('/hi', function(req, res, next) {
    res.send('It is GET');
});

module.exports = router;

express-post-server.js:
const express = require('express');
const bar = require('./express-post');
const app = express();

// curl -X GET http://localhost:3000/foo
app.get('/foo', function (req, res, next) {
    res.send('This is foo GET!');
});

// register
app.use('/bar', bar);

app.listen(3000);

For complete running example clone node-cheat and run node express-post.

