can't you install a private npm module by npm link? That won't touch the npm servers [1]. Then your other project in the same file system can just require like a first class public npm module. [1] https://www.npmjs.org/doc/cli/npm-link.html
How do you go about setting these links when you freshly checked out a project through source control? There is no "npm link all", is there?
How I Work Around The require(“../../../../../../../”) Problem In NodeJS
11–20 of 44 posts
Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#12can't you install a private npm module by npm link? That won't touch the npm servers [1]. Then your other project in the same file system can just require like a first class public npm module. [1] https://www.npmjs.org/doc/cli/npm-link.html
Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#13Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#14Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#15Consider:
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 my perspective on the module when this happens. The shift is from "This code is in a separate module to keep my application organized" to "This code is in a separate module because it has some logical independence from the application.")
If the module needed even more independence, I'd move it to it's own git repo and create an internal mirror of the npm repo so that it can be discovered internally, and unbundle it from my app. (I could see this happening especially with larger teams, or teams that embrace the "module all the things" philosophy.)
And of course, there's always the possibility of moving the module out to the public npm repos and hosting it there.
I've never had require with relative paths of more than two or three "double dots". (Note to self: Look up what those things are called formally.)
Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#16Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#17Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#18For example, if your package is called my-node-module and you have something in my-node-module/lib/app/dir/thingy/wotsit/jimminy.js, it can reference something in my-node-module/lib/server/alf.js by simply going
require("my-node-module/lib/server/alf.js");
There's no need for the relative path at all. It's possible that this only works if your package is in an node_modules directory (which it will be if it's installed as a dependency), but I always symlink my development directory to node_modules anyway.Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#19I am not sure all your private code on git should be publicly accessible. Wouldn't it be possible to point dependency to private in-house GIT repository?
https://www.npmjs.org/doc/install.html
You can also use your own npm registy using `--registry`:
Re: How I Work Around The require(“../../../../../../../”) Problem In NodeJS
#20Usage is as follows:
var pRequire("./projectRequire")(rootPathOfYourProject);
var MyModule = pRequire("~/lib/foo/bar/myModule");
It doesn't really buy you anything over `require("nameOfYourPackage/path/to/module")`, but I like the consistent "~" prefix across projects using the same scheme.Moving things to their own NPM package is a great solution when its something re-usable that logically makes sense to exist on it's own, but that isn't the case most of the time.