relatively
For the Node `require('../../../../../../..')` problem.
Last updated 5 years ago by jmm .
MIT · Original npm · Tarball · package.json
$ cnpm install relatively 
SYNC missed versions from official npm registry.

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.

Demo

Use case

// Before
require("../../../../../../../whatever");

// After
require("app/whatever");

Features

  • Only needs to be invoked at app launch. Doesn't require any changes to modules, they just call require() normally (except with the paths you configure).
  • Uses only public Node API.
  • More flexible than NODE_PATH.

Usage

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

Current Tags

  • 0.1.2                                ...           latest (5 years ago)

3 Versions

  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |