"npm root" locates the global node modules directory
Written by Stefan Judis
- Published at
- Updated at
- Reading time
- 1min
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
. 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:
#!/bin/bash
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!
If you enjoyed this article...
Join 5.4k readers and learn something new every week with Web Weekly.