How often does this happen to you?

Hmm I need to install the nodemon package, ok so I enter:
npm install -g nodemon
npm WARN
npm WARN
npm ERR
npm ERR
npm ERR....

I then wonder why would it not work??? Then after looking at the errors I realise ohh:
sudo npm install -g nodemon

This literally happens to me almost every single time I install a package.

  • 4
    Ehh, isn't there some kind of user-level install? Using sudo sounds like a bad idea for installing packages, at least in python
  • 5
    @alexbrooklyn Not if you're installing it globally. Which begs the question, who still installs these things globally if you can (and SHOULD) put it as a devDepenedency and just run npx nodemon / yarn nodemon?
  • 0
    -g dumps to /usr/local/lib/node_modules, so it shouldn't need sudo. I would suspect if it needs sudo, it's because it's building something.
  • 1
    @alexbrooklyn didn't I somehow manage to do that when I set that fresh vm up for docker?

    It wasn't just the global flag, something about the way i installed it required everything as to be done as root. I think chmod fixed it
  • 0
    @M1sf3t you did a lot of things in that vm :p
  • 0
    You broke something
  • 0
    @SortOfTested Since when directories in /usr/local are writable by anyone except root?
  • 0
    Seems like full rwxrwx+a on all the arch and fedora installs I have. Maybe someone has gremlin'd my machines? ­čś«
  • 1
    I don't trust all those npm packages at all so i do it all in a container. Prevents these issues as well :)
  • 0
    @SortOfTested It varies by the system & install method, debian-based systems + NodeSource put it in /usr/lib/node_modules, and last time I checked that folder was 755 root:root.

    Just to add to my previous comment, it is possible to install "global" node modules in your home directory by setting a bunch of env variables, but it doesn't always work.
Add Comment