Search code examples
javascriptnode.jssails.jsiptablesports

How deal with NVM in production environments?


I am using NVM to develop a Sails web application. I have installed node v0.12.7, through NVM and I use this version to run the website.

nvm use 0.12.7
sails lift

Sails uses port 1337 by default, but for production environment we change it to 443. The problem is that this port requires root privileges, and NVM is installed for just one user. So if I try sudo sails lift, I get an error saying that sails is not installed.

What is the most effective way for dealing with that issue? How can I use NVM to develop my project and deploy it?

I have thought different possible solutions but I don't know if they are good or insecure.

  1. Forwarding ports using iptables. The problem with that is socket could not works beacuse a proxy.
  2. Change permissions for a port. Could be security risk if node have vulnerabilities.
  3. Install NVM with root. The problem is that I uses NVM to avoid use sudo for deploy or run applications, and this will force me to do it.

What are the best practices in this context?

Thanks in advance.


Solution

  • For security reasons it is not recommended to have NodeJS running with root privileges.

    You can try running your application on a port accessible for a different user without root privileges and then configure a reverse proxy from on the 443 port. This is what I did using nginx as the reverse proxy which can be configured easily to perform this task as well as handling the SSL traffic.

    On this link you can find more information about configuring nginx as reverse proxy, it is from the official documentation: https://www.nginx.com/resources/admin-guide/reverse-proxy/