Question

is there a way to run a background node js service along side my website

hi, I’d like to have a node service periodically query an external database (influxdatacloud) for one value that would be stored in the file system and used cosmetically in my site. Is it possible to do this in my droplet?

Subscribe
Share

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

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.

Hello,

You could achieve this with pm2 that way your Node application will run in the background and would be restarted in case it crashes.

You can follow the steps on how to do that here:

All commands used in the video can be found here:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04

Best,

Bobby

Hi @BigElectricBlueWalrus,

Yes, it’s possible and easy to configure. You can install and configure the NodeJS service to query the external database and turn it on on your Droplet like you would usually. All you need to do is have your NodeJS service listen on a different port than 80 and 443 and that is it.

If you want your NodeJS to listen to port 80 and 443 alongside your website, all you need to configure is reverse proxy on your WebService. Both Apache and Nginx do allow it so it won’t be a problem.