Add your Node user. If Apache or something else this could be www-data
.
sudo adduser nodejs
Add users to that group to allow access to the www
directory.
sudo usermod -aG nodejs <username>
Change the group of www
folder.
sudo chgrp -R nodejs /var/www
Give the group read/write access.
sudo chmod -R g+rw /var/www
Force new files and directories to use the same permissions.
find /var/www -type d -print0 | sudo xargs -0 chmod g+s