Artboard 16light, inspiration, solution, idea, innovation,Google Sheets iconSwift icon
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 ./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:

#!/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!

Related Topics

Related Articles