1

I am trying to post files using HTTP request on Node.js ,but after some files posted then it randomly shows [Error: socket hang up] code: 'ECONNRESET'

My code for file sending is,

var http = require('http');
var request = require('request');
var fs= require('fs');
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

var serverUrl='http://localhost:3000'; 

function uploadFile(){
 var req = request.post(serverUrl+'/api/file/upload', function (err, resp, body) {
 if (err) {
     console.log(err);
   } else {
      console.log(body);
   }
 });
 var form = req.form();
 form.append('file', fs.createReadStream('abcd.mp3'));
}

uploadFile();

server.listen(8000);
Sabreena
  • 619
  • 2
  • 11
  • 25
  • Check this http://stackoverflow.com/questions/17245881/node-js-econnreset I think might help you – ayxos Mar 17 '17 at 11:13
  • Perhaps this other answer might help you? https://stackoverflow.com/questions/16995184/nodejs-what-does-socket-hang-up-actually-mean – Lucio Mollinedo Jun 14 '17 at 17:25

0 Answers0