"
SSH into your Droplet and modify this script at /var/www/html/hello.js`` and see the results live by calling
pm2 restart helloRun
pm2 listto see code scheduled to start at boot time Run
pm2 delete helloto stop running this script and
pm2 save``` to stop it from running on Droplet boot
SSH into your Droplet, and git clone your NodeJS code onto the droplet, anywhere you like Note: If you're not using a source control, you can directly upload the files to your droplet using SFTP.
cd
into the directory where your NodeJS code lives, and install any dependencies. For example, if you have a package.json
file, run npm install
.
Launch your app by calling pm2 start <your-file>
, then map the port your app runs on to an HTTP URL by running nano /etc/nginx/sites-available/default
and adding another location. Use the existing entry for the port 3000 "hello" app as a basis.
Call sudo systemctl restart nginx
to enable your new nginx config.
Call ``pm2``` save to schedule your code to run at launch.
Repeat these steps for any other NodeJS apps that need to run concurrently -- schedule them to run at boot time on whatever internal port you like using PM2, then map that port to an HTTP/HTTPS URL in the nginx config. Build out the URL directory structure you need by mapping applications to URL paths; that's the reverse proxy method in a nutshell!