Search code examples
node.jsbitnamiamazon-lightsail

Node.js app stops working as soon as the AWS Lightsail's Bitnami console is closed


I have developed a simple node.js application and I am trying to publish it on AWS Lightsail. I followed the instructions on this page: https://medium.com/@sharmasha2nk/aws-lightsail-bitnami-nodejs-letsencrypt-cf653573b8a1 I am connecting to Bitnami using the SHH console provided. After I start the app with node index.js command the app is up and running until I close the SHH console. As soon as I close it the application stops and “Service Unavailable” error is being displayed. How can I keep my app running on AWS even if my PC is shot down and the SHH console is closed?

I have tried restarting the apache server and AWS Lightsail instance. Neither of them helped.

httpd-app.conf file content:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/

httpd-prefix.conf file content:
Include "/opt/bitnami/apps/emsnotes/conf/httpd-app.conf"

Thanks.


Solution

  • I would recommend you pm2

    Here's how to do it quickly:

    1. install pm2 globally using sudo npm i -g pm2
    2. navigate to the location of your index.js via ssh
    3. run pm2 start index.js

    This will keep node running even when you disconnect the ssh session or shutdown your development computer. The process will keep running on your server in the background. This is used for running node apps in production on a server.

    You can read all about it here in its documentation.

    I hope I could help you, please let me know if you have any question.

    Karim