Any way to fix socket hang up problem?


If i use this code in my project Error socket hang up error show up

const http = require('http');
const express = require('express');
const app = express();
app.get("/", (request, response) => {
  console.log( + " Ping Received");
setInterval(() => {
}, 280000);

But removing it makes my project damn slow!! I used other way to keep my project like using websocket. But still it is not working as expected it is so slow.

EDIT BY ADMIN: I modified your post so that the code is well formatted.


If you’re using express, why are you making a http (node.js http) server?


I found it online and it helps my project to run fast. So i am using it.


Try to respond something when you get the ping:

app.get("/", (request, response) => {
  console.log( + " Ping Received");


Oh I’m stupid, your minified code made me confused and I thought you used http for the server and not for pinging


I will try
Thanks sir!
It’s fixed for now. May it(this bug) never come back!


Sure, it did help you out. By the way, it wasn’t a bug. :man_facepalming:


Did you can check my project it’s again here . If you can help me by making it restart when this error occurs i will be helped so much!:smiley:


Anyone can help me now?


This is happening to me too :frowning:


Did you found a fix?


Hello @ArunKapil01

Your node.js app needs something to keep it alive, some sort of event that has to happen in next tick. For example when you’re using an interval to keep it alive which makes the node.js process always have a task to do.

Here’s an example of an app that will live forever:

// Create an interval to keep the process alive.
const interval = setInterval(() => {
  // So, the deal is, nothing really needs to happen here.
}, 3600*24*365)

console.log('Cat', 'Dog', 'Bird')
console.log('Whatever, this app is immortal.')


That’s actually not true. Your website address needs to be pinged every 5 minutes. My program would always be doing something but it cannot stay alive.


You can use uptimerobot


This doesn’t made my project live!


Hello @lieuwe_berg

Well, would you please explain to me why I have a discord bot, that does not host any http nor https servers, nor does it makes any http (or https) requests to any platform except Discord.

Anyways, if you guys have this issue, that a http server must be hosted, this just might be the very shortest fix.



:man_shrugging: I have to do it that way.


Using setInterval() to keep a bot awake isn’t recommended as it will not be restarted if we have to stop projects. Providing an end-point to ping is a better approach.


This doesn’t gonna help anyway to fix Socket hang up what’s causing this again.


i found works well. You make an account and make a new cron job. You set the adress as (projectname) . you set the shedule to every 5 min (or less) and create cronjob ( You don’t need an html file on your project