NodeJS Server Hosted on Heroku Shuts Down After Some Time - node.js

I am hosting a nodejs (express) server using socket.io on Heroku. After a certain amount of time, I will be unable to access the server from a client - the socket requests will not receive a response. However, once I reload the root web page, I am able to access it. Why is this the case?

I figured out that I need to upgrade to paid (hobby at minimum) Dynos, otherwise the app will go to sleep after 30 minutes of inactivity.

Related

Any good ideas to fix “connect() failed (111: Connection refused)” error when restarting nodejs server?

Background:
I use a Nginx+NodeJS structure to run the website. The server has quite some traffic like 300 concurrent people online. Visiting all kind of pages. And I use pm2 to manage my node apps.
Problem:
However, when I restart the node server with pm2 restart xxx, in a short duration (like 15 seconds), the users will encounter a 502 error. And accordingly, there is “connect() failed (111: Connection refused)” in the log.
According to one other question on SO.
A 502 Bad Gateway error usually suggests that the proxy (Nginx in NodeJS's case) can't find a destination to route the traffic to.
So I guess the error is occurring because of the moment that a user requests the server while the Node hasn't ready for its business. So my Nginx couldn't "contact" my nodejs and threw a 502 error.
Is there any way to fix this?
If you want to continue serving your users while you restart your Node.js server, you need a second Node.js server. More precisely:
Before the restart, node myapp.js is running and listening on port A. Nginx routes traffic to port A.
Now you can start a second Node.js server, probably on a newer version of your app, node mynewapp.js, that listens on port B. While you do that, traffic is still routed to port A.
Once node mynewapp.js is up and running, you switch Nginx so that it routes traffic to port B.
Allow a grace period for requests on port A to finish, then you can shut down the node myapp.js process.
Note two potential pitfalls with this approach:
Long running requests on port A would prevent you from shutting down the "old" Node.js server.
Requests that leave a state in the Node.js server (in global Javascript variables, say), would lose that state when you switch over to the other Node.js server. But (session) states that you write to a database will survive.

IISNode application needs to be restarted every a while

I'm hosting a node application on iis using iisnode.
Every a while, which mostly be every day, the application doesn't receive any request, although there are requests from frontend. When I restart the application, it accepts requests smoothly.
Note: this application is on production and has a heavy traffic.
Any ideas?

Make thousands of connection to websocket

I have node js app with websocket
And deploy on ubunto service i want to know how may connection can this server handed before ram and cpu full
Is there any tool to make thousands of connect and manage it ?

Node server stop responding to requests after a while

I recently created an e-commerce site using express and the node server worked fine on my local machine. When I uploaded it to my VPS and tried running it using pm2 and with nodemon, the server stopped responding to requests after few minutes, even when the number of requests is low.
Although all the internal functionalities other than request handling were working well. I used a lot of console.log()s in my codes, is this problem due to the excessive use of console.log()?

Node.js intermittent connection refused in development

When I run my node.js app in development I intermittently see connection refused an about every 2nd or 3rd request. I am not even sending the requests very quickly (about 1 per second). The requests should be completing very quickly as this is an express app with an end-point that is just checking if the content-type is set correctly. Is it likely that I am seeing the issue because I am not proxying the requests through nginx? Nginx would queue the requests; whereas not using nginx would mean that I am just hitting my node.js app directly. I don't see anything in my node.js app's logs that would indicate an error.

Resources