Live data from Hacker News

How I Work Around The require(“../../../../../../../”) Problem In NodeJS

lostechies.com

41–44 of 44 posts

Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS

#42
I think the best solution for this would be having a private npm server. With npm's recent incorporation and funding, I have a feeling that is going to be coming soon. It's helpful even for small companies, but once you have multiple internal projects all with inter-dependencies that can't be put out publically, it's pretty much a must.

Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS

#43
post #26
post #15

For me, a relative path in a require statement signifies that the required code is a part of the application itself. Consider: require('foo'); Versus: require('./foo'); If I find that a module is becoming popular, I may turn it into an npm module by moving it to it's own folder and adding a package.json, then using npm's bundledDependencies property to inform npm that it lives locally. (edit: Note that I've shifted m…

If find it's easier to distinguish modules from files by requiring modules like: require('foo'); and application files like: require('./foo.js'); //.js extension

Imagine if you're requiring that local module throughout your codebase. Now suppose that the module has become large enough to be come a directory. All those requires with the .js extension will break! If you leave it off, then no problem. Always avoid adding the .js.

Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS

#44
post #27
post #12

Earlier quoted context omitted.

I don't think npm link is meant to be used in production like that.

You probably shouldn't be using npm for production builds. npm is good for libraries, but applications should probably be tarballed.

That was point of the article: npm is not a valid option for various reasons, but it should be easier for applications to organize the source code in multiple directories which you then tarball.
Post reply on HN