require-up

0.4.0 • Public • Published

Require-up

npm

Require modules from anywhere up the parent directories. Like find-up but for require.

Optionally, a new syntax ('.../') which will work with regular require/import calls.

Install

$ npm install --save require-up

Usage

If you have a structure like this:

proj
├───index.js
├───utils.js
└───foo
    └───bar
        └───some-file.js
// proj/foo/bar/some-file.js
const requireUp = require('require-up')
const { utils } = requireUp('utils')

It will look for (in this order):

proj/foo/bar/node_modules/utils
proj/foo/bar/utils
proj/foo/node_modules/utils
proj/foo/utils
proj/node_modules/utils
proj/utils # << found

Register

A new syntax ('.../') which will work with regular require/import calls.

// proj/index.js
import 'require-up/register'
// proj/foo/bar/some-file.js
import utils from '.../utils'

CAUTION

BEWARE: Registering new syntax patches core module.js's Module._resolveFilename.

Readme

Keywords

none

Package Sidebar

Install

npm i require-up

Weekly Downloads

11

Version

0.4.0

License

ISC

Last publish

Collaborators

  • laggingreflex