javascript - Why POST's requests don't parse? -


learn express , faced problem. after create module body-parser begin don't work. requests complited, data don't parsing.

let express        = require('express'); let bp             = require('body-parser'); let dishrouter     = require('./dishrouter'); let app            = express(); let hostname       = 'localhost'; let port           = 8080;  dishrouter.use(bp.json()); //don't work  app.use('/dishes', dishrouter); app.use(express.static(__dirname + '/public')); app.listen(port, hostname, function(){     console.log(__dirname);     console.log(`server has running @ http://${hostname}:${port}`); }); 

//my dishrouter module

let express = require('express'); let router  = express.router();  router.route('/') .all(function(req, res, next){     res.writehead(200, {'content-type': 'text/plain'});     next(); }) .get(function(req, res, next){     res.end('we dish you'); }) .post(function(req, res, next){     res.end('will add dish:' + req.body.name + ' details: ' + req.body.description); }) .delete(function(req, res, next){     res.end('deleting dishes'); });  module.exports = router; 

as example miss send after rest:

app.route('/book')   .get(function(req, res) {     res.send('get random book');   })   .post(function(req, res) {     res.send('add book');   })   .put(function(req, res) {     res.send('update book');   }); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -