Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript npm Basics Installing Packages with npm Installing Local Packages

James Estrada
seal-mask
.a{fill-rule:evenodd;}techdegree
James Estrada
Full Stack JavaScript Techdegree Student 25,862 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?