What is the proper way of using npm in root environment?

294 views Asked by At

I'm currently setting up a Parse Server with AWS EC2 instance, where I've been using Nginx and Elastic IP to manage SSL certificates. Through different guides I've reached the solution of put the node app at /var/www/parse-server, but they say I should do 'npm init' in this directory, which is obviously owned by root (and fails because of permissions, of course).

My question is about the proper way of manipulate the app files in this root path, specially because 'sudo npm init' has conflicts with packages when the project keep moving on.

  • Should I use 'sudo su' and proceed with the install? I tried to do that, but npm init isn't recognized as a command. I haven't tried with --prefix yet, because I wanted to make sure before do that.
  • Should I use another directory to keep my application working? I've though that, but what about Nginx and all the related config?
  • Should I chown -R the folder to gain ownership of the /var/www/parse-server folder? If I do that, what about permissions later on?
1

There are 1 answers

0
Wladimir On BEST ANSWER

I found two workarounds for this:

  1. chown -R to change the directory owner to my own user. This works but i think is not the proper way.
  2. Proxy reverse to the specific folder (i'm using nginx, so whoever is watching this thread should be fine with nginx docs)

Thanks to Davi Macedo for solution 1.