In “Development to production in less than 5 minutes”, we have discussed how to deploy a NodeJS application on a VPS. Today we will learn how to deploy more NodeJS applications on the same VPS. There are a lot of reasons to do that. For example — we have three or four small, static applications and we want to make them live. If we have one small app on a single VPS, we are just wasting a lot of VPS resources. In order to use a VPS to its limit, we can host multiple application without paying for another VPS.
Before doing all this, first we will make sure that we know what is the difference between a web server and an app server. So lets start…
Before proceeding further, you must know how to deploy Node application on a server.
⚠️ I have a separate blog post for this, I recommend to first go through that one and then we will proceed further.
let’s get started
⚜️ Web Server vs App Server
Web server is basically the one who will first receive the request from the outer world. It is the one who is responsible for handling all the requests. Web server will just handle the request and pass it over to the app server so that app server will process this request and send the response back to the web server so that it will send that response to the client who make this request.
Web Server provides environment to run App server
Web Server — Handles the request, serves content to the web using http protocol
App Server — Process the request, hosts and exposes business logic and processes.
- Configure Dokku with domain name
- Create sub-domain for your application
- Add remote into NodeJS app
- Push Code to Remote
1. Configure Dokku with domain name
After creating the droplet ( As described in the previous post ), when you enter the IP address of your VPS into the address bar of your browser. You will see Dokku configurations.
At there, instead of IP in hostname, change it with your registered domain name. Make sure to select Use virtualhost naming for apps. After this, click on Finish Setup.
2. Create sub-domain for your application
After configuring Dokku, visit your Digitalocean account and then click on Networking. If you have already linked you domain name with Digitalocean account, select your domain name else first link it by clicking on Add Domain button.
Then create a A-Record by entering the subdomain you want to connect your application with. i.e if you want to open you application at xx.doe.xyz just enter ‘xx’ and it will automatically suffixed before your domain name.
Select the VPS you want to connect your subdomain with or in other words, select the one on which we want to deploy our application.
3. Add remote into NodeJS app
After doing all this, now open a terminal window and change your directory to the root of the application you want to deploy.
Add a remote by executing the following command.
git remote add dokku firstname.lastname@example.org:xx
Make sure you typed the exact address that you have entered while creating sub-domain on DigitalOcean. The ‘xx’ after
:, this is the name of the application which dokku will use to deploy at.
⚠️ Make sure you have the same sub-domain and app-name.
4. Push Code to Remote
Now the last step, just push your code to Dokku and it will handle the rest of the work.
⏳ Just wait until the deployment ends
Dokku will create a new app with the name that we have passed in remote. It will auto configure the nginx to use this app if the request is came for this app. i.e if you request
xx.doe.com dokku will redirect that request to that app which is named as
xx and if you request for
yy.doe.com , the
yy will handle that request.
That is why keeping the same name of the subdomain and the app-name in Dokku will solve a lot of confusion
Today we learned how to deploy multiple NodeJS applications on single VPS. Now we can host more than one application on single server.
About this post
This post has a predecessor “Development to production in less than 5 minutes”.
There will be lot more interesting stories about web development in future. Next story will be on next Monday Morning at 08:00 AM (UTC+05:30). Stay tuned!
Happy Coding !!
🎧 Listening to “Zack Hemsey — “The Way (Instrumental)”, Simply Beautiful and peaceful. Must listen if you want concentration.
If you like this article, please give it some claps 👏 and share it! If you do not like this post or have any type of questions regarding anything that i mentioned in this post. Feel free to ask me. Just post an issue in my “Ask Me Anything” by clicking here.
Don’t forget to 👆 subscribe our weekly-newsletter service for web hackers. All latest articles and stuff like trending repositories, straight to your mailbox 📬.