As for the rest of the settings, like plan and datacenter region you can choose whatever you want. For this guide, the $5 plan is sufficient, but you can choose a higher one if you want.

Connect to the remote server

Next, you’ll need to connect to the remote server using SSH. Upon creating the droplet, you should’ve received an email containing login credentials for the server (IP address, username, and password).

Use this command in the terminal to connect to your server:

ssh <user>@<ip-address> # e.g. ssh root@123.45.67.890

After you’ve typed in the command, you’ll be prompted to enter a password (this is the password that you received in the email). You’ll also be asked to create a new password.

Fetch your project using git

I’m assuming that you store your code on a git repository, i.e. Github or Bitbucket. If you are, simply clone your project using this command:

git clone <url-to-your-project>

After cloning the project, switch to your project directory:

cd ./<your-project>

Change the port to 80

An important thing to know is that HTTP is using port 80 as a default port. Meaning, if you’re trying to access a webpage without specifying the port number, it will automatically try to connect to port 80.

DigitalOcean is also blocking all ports on the droplet by default, except from port 80 (HTTP), 443 (HTTPS) and 22 (SSH). Therefore, in able to access the web app from outside, you’ll need to change the port number to 80.

It will maybe be easier to do this in an editor on your machine and then commit the changes to git. But you can also just edit the file in a terminal-based code editor like Vim or Nano.

Install and start the app

Next and final step will be to install the web app and get it up and running. Run whatever install script you’ll need to run (if needed), and then start the app.

# Install the app

npm install # Run the app

node app.js

Now, visit the droplet’s IP address and voilà! Your first Node.js app — live and accessible for everyone to visit.

Troubleshooting

If your web app doesn’t respond when you visit the IP address, try to change the hostname in your Node.js app from localhost or 127.0.0.1 to 0.0.0.0.

Conclusion

Deploying a Node web app is actually really easy and straightforward once you get the hang of it. The only thing you need is a web app and a remote server, e.g a VPS. It may also be handy to know how to navigate around in a terminal.

As for cloud-based hosting, DigitalOcean is a great VPS provider. It’s simple to use and easy to create and manage droplets. It’s also perfect for doing quick and short test runs. If you look for a cloud service provider, I would really recommend using DigitalOcean.

And as promised, here is a referral link that will give you $50 credit for 30 days. Enjoy!

DigitalOcean referral link: https://m.do.co/c/4229ad372d48