Artboard 16Google Sheets iconSwift icon
Published at
Updated at
Reading time
This post is part of my Today I learned series in which I share all my web development learnings.

Today I learned that the npm root command locates the local and global node_modules directory.

Finding local dependencies isn't very spectacular because they're usually located in ./node_modules. But locating the global dependencies can be a hassle. People install Node.js in countless ways, and that's why the Node.js binary and the global dependencies can be anywhere.

It's great to learn that there's a command that helps locate the global dependencies!

From the npm docs:

global_node_modules="$(npm root --global)"
echo "Global packages installed in: ${global_node_modules}"

And I just had a use case for npm root. Beautiful!

Was this TIL post helpful?
Yes? Cool! You might want to check out Web Weekly for more quick learnings. The last edition went out 3 days ago.

Related Topics

Related Articles