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

when i run my web application i get this error.this was happened suddenly.my application is MEAN stack

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745340343a4623298.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信