I'd like to break the bad habit of installing npm global packages by using sudo.
I already have seen answers about how to avoid sudo by switching to using your home directory, like this: Ensure npm install -g does not need sudo?
But I've already installed a bunch of stuff globally using sudo. I want to take all that stuff with me that's installed as root into my new home directory for npm. Is there a way to do that, or am I essentially starting over from scratch having to re-install everything that I had installed before?
Having not seen a better answer yet, I went forward with doing this:
npm list -g --depth=0
...to see what I already had installed globally. Then I followed the steps here: https://docs.npmjs.com/getting-started/fixing-npm-permissions
...to set up npm in my home directory, then I reinstalled everything (which turned out not to be a huge amount of stuff) I got from "npm list -g --depth=0".
So far, so good. I'd still be curious to know if there's a better approach.