Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only ignore the node_modules directory in project root. #1336

Closed
wants to merge 1 commit into from

Conversation

pygeek
Copy link

@pygeek pygeek commented Dec 26, 2014

.gitignore - node

Ignoring /node_modules, which is populated upon installing an npm module is good. Ignoring lib/node_modules is bad. Having a lib/node_modules directory in your project is optimal if you have submodules in your project you want to reference.

"Furthermore, to make the module lookup process even more optimal, rather than putting packages directly in /usr/lib/node, we could put them in /usr/lib/node_modules//. Then node will not bother looking for missing dependencies in /usr/node_modules or /node_modules.

In order to make modules available to the node REPL, it might be useful to also add the /usr/lib/node_modules folder to the $NODE_PATH environment variable. Since the module lookups using node_modules folders are all relative, and based on the real path of the files making the calls to require(), the packages themselves can be anywhere."

Ref: http://nodejs.org/api/modules.html#modules_addenda_package_manager_tips

Ignoring /node_modules, which is populated upon installing an npm module is good. Ignoring lib/node_modules is bad. Having a lib/node_modules directory in your project is optimal if you have submodules in your project you want to reference.

"Furthermore, to make the module lookup process even more optimal, rather than putting packages directly in /usr/lib/node, we could put them in /usr/lib/node_modules/<name>/<version>. Then node will not bother looking for missing dependencies in /usr/node_modules or /node_modules.

In order to make modules available to the node REPL, it might be useful to also add the /usr/lib/node_modules folder to the $NODE_PATH environment variable. Since the module lookups using node_modules folders are all relative, and based on the real path of the files making the calls to require(), the packages themselves can be anywhere."

Ref: http://nodejs.org/api/modules.html#modules_addenda_package_manager_tips
@arcresu
Copy link
Contributor

arcresu commented Jan 7, 2015

I'm not sure if I'm misunderstanding that documentation but it seems that (a) that's a hypothetical paragraphs rather than a recommendation, (b) is talking about local system-wide installation of packages. It seems to have no bearing on what to do with individual projects. Can you clarify this, maybe give an example? Thanks!

@shiftkey
Copy link
Member

@pygeek unfortunately this isn't mergeable currently, and there are some questions outstanding which we'd like to clarify before merging 😢

I need to clean up stale pull requests at some stage, and will close this out if I don't hear anything before Friday 26th February.

@pygeek
Copy link
Author

pygeek commented Jan 27, 2016

A year later, and I haven't needed to use this convention often. It's useful if you're creating a sub modules in your project and wanted to import them without having to use relative paths, which are suboptimal for maintenance reasons. See comments on this thread: https://gist.github.com/branneman/8048520

This PR was intended satisfy the the normal use case, and the case where someone needs to use lib/node_modules.

There would be one potential issue—if the root directory of the repository was not the root of the project it would fail to ignore any node_modules. I'll be updating this pull request to instead add a line to not ignore any instances where node_modules is directly within a lib folder and everyone should be happy.

@pygeek
Copy link
Author

pygeek commented Jan 27, 2016

I use a different convention for doing this now. This PR can be closed now without remorse. :-)

@shiftkey
Copy link
Member

@pygeek thanks for coming back to this! I've had people tell me lots of things about what they do with their node_modules folders over the years - some of it often conflicts with what others do, so I always find this stuff fraught with danger!

@shiftkey shiftkey closed this Jan 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants