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

louis wong
louis wong
5,842 Points

Does node_modules folder have to be in the same root as the app.js file?

when i did npm install my node_modules folders are separated from my app.js file, but what is confusing is that why is it still working? And also what happens when i upload my code onto a server where will it be getting the node_modules from since the node_modules are installed locally?

Oliver Duncan
Oliver Duncan
16,642 Points

It's been a while since I worked with Node, but I think as long as node_modules is in your project directory, you're good to go. When you upload to a server, say to publish your site, you'll be uploading the whole project directory, so your modules will go with it. However, I'm not sure what happens when you use global modules...more research is needed.

1 Answer

Alisdair Buttery
Alisdair Buttery
2,534 Points

Your app.js and node_modules folder should be separate from one another so as long as the app.js is in the project root along with the node_modules folder then everything should work fine.

As for how this works on a server; it really depends on how you are using node.js. If you are using it locally to build static files before uploading them to the server then you don't need the node_modules folder on the production server.