MEAN Stack Express server going down - node.js

I am running a Node.JS + Angular JS application on a cloud server using the MEAN stack. The application is terminating every hour or sooner.
I have few thoughts and would like someone who can tell me which might a cause.
I am using SSH through root when I start the service using this command
NODE_ENV=production PORT=80 grunt serve:dist
Do I need forever to run this properly ?
Should I use a server user (similar to apache) that can run the application?
If yes how do I do this ?
We do not have a deployment engineer in our team but it is annoying to not being able to keep the app running on the server after developing the application. Please help diagnose the problem.

If you don't want to use a deployment service — MS azure, AWS, heroku, etc. (which would probably be a lot easier) — then yes, you would have to use something like forever to restart your sever every time it crashes. It's really odd that your app terminates after an hour though, it'd be helpful if you could describe why that's happening.

Related

How can i access nodejs terminal in production to view run time errors

I want to access node app terminal in production if there is a way, as in development we can access terminal to see activities, events and log messages, but in production(cPanel) i did not find such tool which i can use to view runtime error to solve any error in the code.
If you know any solution regard this problem, please answer me, i am looking very seriously at it.Thanks, any help will be appriciated
You're welcome 🙏🏼
Shared hosts do not have access to the terminal at all
You have to buy the virtual private server (VPS) so you can run your nodejs app and access terminal.
Use pm2 for production nodejs app.
npm i pm2 -g
PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.

How to run node.js script on ftp server?

I've developed a wallpaper app whose backend is written in node.js . Everything in development was fine then today I bought a vps server with cpanel for 3 months from a hosting service provider .But I'm a complete beginner in server management so now how to run this node.js script in my ftp server . Can anyone please guide me to run node.js script on server ?
It may sound like off-topic but please do help me to fix my problem.
I'm a complete beginner so please do excuse me if my question is foolish.
I think there's no support for using Node.js with cPanel. But I can recommend you to use for example Heroku for testing or hobby development. Heroku is free, very simple and cool for small projects.
If it's just a simple, single node.js script, I'd recommend running this as a lambda function – basically, use a service that will run this script at a given HTTP endpoint without needing to manage a server. This can be free depending on how much it's used. For example, here are some places to run it:
https://blog.cloudflare.com/cloudflare-workers-unleashed/
https://www.netlify.com/docs/functions/
https://aws.amazon.com/lambda/
As CenyGG suggested, Heroku is also a great place to do this and will be free if you don't need the app to be live 24/7 (it will go to sleep and take a few seconds to "wake up" if it hasn't been used in a while).

Deploy node.js server application (best practice)

I wonder if my way to deploy of node.js application is good or can be improved and how, and if there are some best practices.
Consider it's a large application and can contains unhandled exeption that will make the node server crash (even using unit test, we're not sure it's 100% crash safe) I use forever for make the server always running (I could also use pm2, but the pourpose it's the same). So I build a systemd script for use this as service like "service nodeapp start|stop|status"
I think the best solution it's run node "raw" without forever or pm2, still using systemd, but I think the risk of crashes it's too high.
The server it's behind a nginx proxy, and I also added logrotate script for log maintenance.
Any advice and suggestions will be greatly appreciated
Thanks
There are plenty of checklists both on the internet and here on stackoverflow.
My personal checklist is:
setting node_env to staging
run all the unit tests
deploy on a staging env
run all the scripts on the server
if tests passes change node_env on prod and deploy
If you want to skip some tests and be sure that the environament is the same on dev and prod there is a fairly new things called docker but in the first time ot will add some complexity.
Hopefully when you have all setted down with docker it should not be too much intrusive.
Ps. Use forever, if you're using docker you could restart the container but it's not that great

How are most Node applications started?

I know to start my Node app I type in the Win shell, node app.js.
But this is obviously not how a webhost would maintain a Node webserver (ie what happens if there is a power outage, a Node exception, etc).
I see things like Forever and running Node as a Windows service, but I feel like the creator of Node must have had a different idea? Something like Apache is installed as a Windows Service so that it runs even if the server reboots - what is the correct method of doing this for Node? I don't like the idea of introducing another piece of software just to keep the server going.
Thanks.
The problem is that many systems do not do that. For instance MongoDB doesn't even run like that on windows.
The best solution I have found is this https://nssm.cc/
Also you have to consider even on Linux you need to run something like upstart to keep node programs running when you close the console.

Starting NodeJS - what code to look for?

We have a whiteboard application powered by NodeJS sitting on a 'cloud' server (rackspace cloud). I recently scaled our server up to accommodate for the anticipated traffic with our launch, and in the process it shut down NodeJS. We are launching our product in a few hours, and our NodeJS developer has gone for the day.
The whiteboard application is supposed to run at http://rayku.com:8001 (the port is opened). However, it's not working because the port isn't listening to anything with NodeJS shut down.
I honestly have no idea which js file to run in order to start NodeJS for the whiteboard. There are many js files in a 'whiteboard' folder. Do you know what type of code I should look for that might suggest it is the right one? Or, do you know what types of logs I can dig up that might point me in the right direction?
Much appreciated
Look for app.js, server.js or something similar. It isn't required but a lot of people use app.js from what I have seen.
node or nodejs is typically the command to start. You may need to set environmental variables or arguments depending on how the developer set things up.
Also make sure to run it with screen or forever so it doesn't quit when you log out.
For common code. createServer is probably what is used to open the server itself. That is consistent between the core libraries and a lot of the frameworks. There might be another file that loads the module prior to executing so running might not work.

Resources