最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Failed to load resource: net::ERR_CONNECTION_REFUSED on NodeJs ,AngularJs Web Application - Stack Overflow

programmeradmin1浏览0评论

when i run my web application i get this error.this was happened suddenly.my application is MEAN stack appllication whicj has a end to end connection through APIs.

Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)
at ServerResponse.res.set.res.header (D:

this is an API that is being exposed.

app.post('/api/filesReadUpload', function(req, res) {

    var eventReadUpload=new filesReadUpload({
      //id:req.body.id,
        dat:req.body.dat,
        details:req.body.details,
        tim:req.body.tim,
      //  space:req.body.space

    });

    eventReadUpload.save(function(err) {
      if (err)
          res.send(err);

      res.json({ message: 'Read file!' });
});
        });

can anyone support with this.if this information is not enough please inform me.

Thanks

when i run my web application i get this error.this was happened suddenly.my application is MEAN stack appllication whicj has a end to end connection through APIs.

Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)
at ServerResponse.res.set.res.header (D:

this is an API that is being exposed.

app.post('/api/filesReadUpload', function(req, res) {

    var eventReadUpload=new filesReadUpload({
      //id:req.body.id,
        dat:req.body.dat,
        details:req.body.details,
        tim:req.body.tim,
      //  space:req.body.space

    });

    eventReadUpload.save(function(err) {
      if (err)
          res.send(err);

      res.json({ message: 'Read file!' });
});
        });

can anyone support with this.if this information is not enough please inform me.

Thanks

Share Improve this question asked May 29, 2017 at 18:00 Shan PeirisShan Peiris 1831 gold badge4 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

The ERR_CONNECTION_REFUSED appears because the server is down. The reason why the server is down is because of the error you pointed:

Error: Can't set headers after they are sent.

That means you tried to send the response twice. In case of error you have to run return res.send(err) because you want to not call the res.json in case of error. If you do (what currently is happening), you will get that error.

eventReadUpload.save(function(err) {
  if (err)
    return res.send(err);

  res.json({
    message: 'Read file!'
  });
});

You will have to figure out why the saving fails, but this will fix the initial problem.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论