Deploying a Node.js Express backend with a MySQL database on Ubuntu Amazon Lightsail VPS

Nirmal Mendis
2 min readApr 13, 2024

--

Photo by Emile Perron on Unsplash

This article requires the following prerequisites to proceed. You can follow the referred articles to complete these steps if not already completed.

  1. Purchasing Amazon Lightsail VPS and logging in using SSH [1]
  2. Install MySQL on Ubuntu VPS Amazon Lightsail [2]
  3. Setting up Node.js and Git on Ubuntu Amazon Lightsail VPS [3]

Once the above prerequisites are complete. Let's start the following steps.

  1. First login to the VPS using a preferred client and create a directory to clone the project.
mkdir project

2. Use Git clone along with the SSH link provided by git for the repository.

 git clone <paste ssh-link here>

3. Use cd and move into the cloned repository folder. Use Vim and create your env file and paste the contents (or you could use a tool like file zilla to copy the env file).

4. Now install npm dependencies

npm i

5. If your NodeJS application uses puppeteer, you might want to install the following as well. (Just keep in mind if you get any error with puppeteer during runtime, try install the following).

npx puppeteer browsers install chrome
sudo apt-get install -y gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
sudo apt-get install -y libgbm-dev

6. Next, start the NodeJS server.

npm start

However, the above will cause the NodeJS server to stop once the terminal is closed.

In order for the NodeJS server to keep running, use the following.

npm start &

If you want the logs to not to appear in the console you could use dev null or you could redirect the logs to a specific text file.

npm start > /dev/null &
npm start > /home/ubuntu/apps/logs.txt &

7. Optionally, setup a custom rule in Lightsail to allow incoming traffic for the NodeJS server port if needed (follow [1]).

This completes the deployment of a NodeJS express application on Amazon Ubuntu lightsail VPS. Cheers! 🥳Feel free to leave any feedback. Thanks!

Reference

  1. Purchasing Amazon Lightsail VPS and logging in using SSH
  2. Install MySQL on Ubuntu VPS Amazon Lightsail
  3. Setting up Node.js and Git on Ubuntu Amazon Lightsail VPS

--

--

No responses yet