Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript npm Basics (retiring) Installing Packages with npm Installing Local Packages

James Estrada
seal-mask
.a{fill-rule:evenodd;}techdegree
James Estrada
Full Stack JavaScript Techdegree Student 25,866 Points

How Does The Path To Files Work?

I have installed npm and bcrypt successfully on my mac and printed out the hashed password. My question is about how it works behind the scenes. My app.js file is located totally in a different directory where bcrypt was installed (user/node_modules/bcrypt). I see on the bcrypt contents the 'package.json' file that points to the bcrypt folder, but in my app.js I give a path of only 'bcrypt' to the require method and not the path where the actual module resides. What is happening here? Why am I not giving a path of '../user/node_module/bcrypt' to the require method? How does JavaScript know where the module is located? Or is npm doing this work behind the scenes?