javascript - could not get response from express.js server using postman -


when make post request postman, request data shown server server response i.e status code , json object not send postman, postman loading... , after time says not response server.

here server.js class

var bodyparser = require('body-parser'); var express = require('express');  var {mongoose} = require('./db/mongoose'); var {todo} = require('./models/todo'); var {users} = require('./models/users');  var app = express(); app.use(bodyparser.json());  app.post('/todos', (req, res) =>{ var todo = new todo({ text: req.body.text });  todo.save().then((doc) => { res.send(doc); }, (e) => { res.status(400).send(e); });  });  app.listen(3000, () =>{ console.log('started @ port 3000'); }); 

there error in executing todo.save console.log(e) check error throwing mongo. can send error in response see going on, instead of writing res.status(400).send(e); write res.send(e) , send error response. "could not response" error happens when haven't send response server. in case sending response promise resolved block not error block.

also make sure todo.save() return promise? may can achieve by

todo.save(function(err,doc){ if(err){ return res.send(err); } res.send(doc); }) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -