3 ms·
Am I the only one that doesn't find this a problem? My usual idiom is to do two things: 1. Part of my boilerplate at the top of every JS file is something lik
by rodw 13y ago
Am I the only one that doesn't find this a problem?
My usual idiom is to do two things:
1. Part of my boilerplate at the top of every JS file is something like this:
var path = require('path');
var HOMEDIR = path.join(__dirname,'..','..');
where `__dirname` is the built-in variable that names the directory that contains the current file, and `'..','..'` is the requisite number of steps up the directory tree to reach the root of the project.
From there is it is simply:
var foo = require(path.join(HOMEDIR,'lib','foo'));
var bar = require(path.join(HOMEDIR,'lib','foo','bar'));
to load an arbitrary file within the project.
2. Long before I got to 8 levels deep in the directory tree I'd create a separate npm module to bundle the code together in a less spaghetti fashion.
For what it's worth, I typically use a branch on a private GitHub repository for my "private" modules. I.e., the master branch has the source code, and another (say, `npm-v1.2.3`) has the npm package of it.