Node Hello World.. with pm2 on an AWS ec2 instance.
Node.js with pm2 (a process manager to help you manage your app online) app for an ec2 environment.
The following guide can help you get started building a AWS Node virtual machine with the powerful process management system pm2.
Guide from ssh connection to deployed app.
This guide will take you step by step on how to deploy a node server with the process manager pm2 on an AWS ec2 virtual machine.
- Make an ssh connection to your aws instance
- Download Node Version Manager (nvm) with: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
- Activate nvm with: . ~/.nvm/nvm.sh
- Install Node with: nvm install node
- Download git with: sudo yum install git
- Clone this simple node hello world server https://github.com/johnpapa/node-hello with git clone https://github.com/johnpapa/node-hello.git
- Navigate to the node-hello directory with: cd node-hello/
- Install pm2 with: npm install -g pm2@3.2.2 (the latest version results in unresolved errors)
- Create a startup script with: pm2 start index.js (index.js is the file to run the server in this repository)
- Create a generate an ecosystem configuration file with: pm2 ecosystem
- Ensure that the script is index.js with: cat ecosystem.config.js

- If it does continue. Otherwise refer to this page for information on how to edit the file so that the script leads to index.js: https://www.howtoforge.com/faq/how-to-edit-files-on-the-command-line.
- Finally run the server with ec2: pm2 reload ecosystem.config.js --env production
- Find your instance's public ip address:

- Add Inbound Rules: head to your aws dashboard -> find and click on 'Security' -> Click on the 'Security groups' url -> click on 'Edit inbound rules' -> create the following rule:
-> click on 'Save rules'
- Navigate to: http://YOUR_INSTANCE_PUBLIC_IP_ADDRESS:3000/
- Congratulations!
npm start