Live data from Hacker News

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

lostechies.com

1–10 of 44 posts

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

#3
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

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

#5
I've done this in the past on *nix systems, for Perl. I modified PERL5LIB from my .bashrc file, so that my project lib was looked for by default. This, rather than having to put 'use lib '../../../yikes/ugly' ahead of any inclusion of project modules.

Another approach, which I favor now, is to place modules directly into the default locations, such as /usr/lib/share/perl5 and etc.--usually there are a number of paths Perl looks at by default. It's then just a matter of saying 'use MyModule;' in code.

Is node.js similar, in having one or more include paths set by default, and could files be put there, to where you never have to refer to something by relative location again?

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

#8

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

The OP did not read npm doc obviously. npm link is the killer feature of npm.

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

#10

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?
Post reply on HN