package
For the Node `require('../../../../../../..')` problem.
npm install relativelyGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
A WIP experimental approach to solving the Node require() ../../../../../../.. problem. See for example Better local require() paths for Node.js. Allows require()ing paths that are relative to the application root, or whatever you configure.
// Before
require("../../../../../../../whatever");
// After
require("app/whatever");require() normally (except with the paths you configure).NODE_PATH.Create an initialization script that you require prior to your normal app entry script:
// init.js
require("relatively")({
mods: [
{
type: "dir",
// Makes `require("app/whatever")` behave like
// `require("/path/to/some/dir/whatever")`, from anywhere in your
// dependency tree.
from: "app",
to: "/path/to/some/dir",
},
]
});// entry.js
// Loads /path/to/some/dir/x/y/z
require("app/x/y/z");node -r ./init.js entry.js