Skip to content

Instantly share code, notes, and snippets.

@odedhb
Last active December 25, 2022 09:48
Show Gist options
  • Save odedhb/c0fa004c52f0cf6fe14748cc6e5da116 to your computer and use it in GitHub Desktop.
Save odedhb/c0fa004c52f0cf6fe14748cc6e5da116 to your computer and use it in GitHub Desktop.
nodeJS-Lightsail

Add a Lightsail Instance

Go to https://lightsail.aws.amazon.com/ls/webapp/home/instances
Click “Create instance” button on top right corner
Create Instance:
Instance Location: us-east-1a
Platform: Linux/Unix
Blueprint: Apps +  OS –> Node.js
Instance Plan: select least expensive
Identify your instance: <your-instance-name>
Create Instance

Deploy your code to Lightsail

SSH into the instance:
Host: Public IP
Port: 22
Username: Bitnami
Key: <aws-key>
Clone git repository (this will also create the parent directory):
git clone <git-clone-link>
cd ~/<directory-name>
Install npm packages:
sudo npm install
Start the server:
sudo npm install pm2 -g
pm2 start dist/server.js --log-date-format 'DD-MM HH:mm:ss.SSS'

If you’d like to Run a branch:

git checkout <branch name>
git pull

if you get this error: error: Your local changes to the following files would be overwritten by checkout: Please commit your changes or stash them before you switch branches:
       git checkout -- .

Add environment variables

for use with process.env.param

sudo nano /opt/bitnami/nodejs/bin/node

example:


#!/bin/sh

export REGION="us-east-1"
export ACCESS_KEY_ID="AAAAAAAAAAAAAAAAAAAA"
export SECRET_ACCESS_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

. /opt/bitnami/scripts/setenv.sh

exec /opt/bitnami/nodejs/bin/.node.bin  "$@"
  • Note: To save: Exit (ctrl+X), Yes (y), Enter

Make the Node Express app work on port 8080

Change the apache settings file:

cd /opt/bitnami/apache2/conf/bitnami

nano bitnami-apps-prefix.conf

Enter this text so that the apache settings file will look at 3000:

ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

restart apache to make your changes count: sudo /opt/bitnami/ctlscript.sh restart apache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment