How do I host 3 node apps with 3 different domains on one droplet?

Hello all. Stuck trying to setup up several Node apps on one droplet. I followed the Host Multiple Node.js Applications On a Single VPS with nginx, forever, and crontab article exactly.

I have the domains all pointed correctly and A records set.

I can’t seem to get apps to run (with forever) on any other port besides the default express 3000.

I changed the server_names_hash_bucket_size 64; (like it says) I created /etc/nginx/conf.d/ for the apps (they are different domains. I put 1 on port 3000 and the other on 4000)

I don’t understand the difference between when Nginx is running the app and when forever is? Where does “npm start” come into play? How many potential servers are working at the same time?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

check out [] or [] if you want to do it the NodeJs/Express way. assume port 8001 is node app A and 8002 is node app B. change to port 80 and nodemon this file.

var bouncy = require(‘bouncy’);

var server = bouncy(function (req, res, bounce) { if ( === ‘’) { bounce(8001); } else if ( === ‘’) { bounce(8002); } else { res.statusCode = 404; res.end(‘no such host’); } }); server.listen(80);

Nginx doesn’t run the app. It is a webserver and it acts as a proxy in this case. The apps are run on a non-standard port and Nginx than relays then to port 80 on the correct domains. <br> <br>Selecting the port to run on, is up to the app itself. Are these apps you’ve written or just things you’ve installed? Usually, you can set the port as an environment variable. So, you’d start your app with something like: <br> <br><pre> <br>PORT= 4000 forever start --sourceDir /path/to/your/node/app main.js <br></pre> <br> <br>That assumes that the app does something like the bellow. This is from the template created using express-generator, so it is fairly universal: <br> <br><pre> <br>#!/usr/bin/env node <br>var debug = require(‘debug’)(‘my-application’); <br>var app = require(‘…/app’); <br> <br>app.set(‘port’, process.env.PORT || 3000); <br> <br>var server = app.listen(app.get(‘port’), function() { <br> debug('Express server listening on port ’ + server.address().port); <br>}); <br></pre> <br> <br>That defaults to using port 3000 unless the environment variable is set.