How can I return a well formatted 201 with Express?

一个人想着一个人 提交于 2019-12-04 16:24:30

The problem is it's trying to parseJSON on a blank response. It's effectively doing jQuery.parseJSON('') - which does produce an error if you try an run it.

To resolve it you could return any string that can be parsed as JSON - e.g. the string null or empty quotes "".

todosRouter.post('/', function(req, res) {
  res.send('null');
  res.status(201).end();
});

todosRouter.post('/', function(req, res) {
  res.send('""');
  res.status(201).end();
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!