Hello! does anyone know why i might be receiving the following error: "ECONNRESET"

I have tested my other API requests and they all give me a status code, status, and the headers without any problems, However for this particular request its giving me the following error and i have no idea why.

Error which I’m receiving:

Error: read ECONNRESET
   at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
errno: -4077,
code: ECONNRESET,
syscall: 'read'
}

Connect function:

function Connect(server, sId, aId, password) {
  console.log("Creating connection")
  var postData = {Server: server, SId: sId, AId: aId, Password: password}
  var strData = JSON.stringify(postData);

  // creating Json web token
  const token = jwt.sign({strData}, process.env.TOKEN_SECRET, {algorithm: "HS512"} );
  MakeConnectionRequest('//path', strData, token); 
}

Below is my client request code:

function MakeConnectionRequest(path, data, token) {

  const options = 
  {
     
    method: 'POST',
    protocol: 'https:',
    hostname: '', // I do have a hostname - keeping empty
    //port: 443,
    path: `${path}`,
    rejectUnauthorized: false,
    headers: {
    'Content-Type': 'application/json',
    'Content-Length': 89,
    'authorisation': `${token}`
    
  },  
};

const request = https.request(options, res => {
  console.log(`statusCode: ${res.statusCode}`)

  res.on('data', d => {
    process.stdout.write(d)
  })
})

request.on('response', (response) => {
  console.log(`STATUS: ${response.statusCode}`);
  console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
  response.on('data', (chunk) => {
    console.log(`BODY: ${chunk}`);
  })
  response.on('end', () => {
    console.log('No more data in response.')
  });
});
request.on('error', error => {
  console.error(error)
})

request.write(data, 'utf-8');
request.end();

}

Is there something I might be doing wrong in my code here? Any advice would be much appreciated!

Thankyou!

Hi,
Seems like upgrading nodejs to the latest version will help:

Hey thanks for the reply! I’ve updated to the latest version of node.js and unfortunately the error still occurs. I’ve been doing more research online and it seems to be a very common issue in v16. Some of the forums I’ve looked at don’t even have any responses for the problem which doesn’t help. :neutral_face: :disappointed:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.