req-cwd

Require a module like `require()` but from the current working directory

Renamed to `import-cwd`.
Last updated 8 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install req-cwd 
SYNC missed versions from official npm registry.

req-cwd Build Status

Require a module like require() but from the current working directory

Install

$ npm install --save req-cwd

Usage

const reqCwd = require('req-cwd');

// Target module is at '/Users/sindresorhus/unicorn/foo.js'

console.log(__dirname);
//=> '/Users/sindresorhus/rainbow'

console.log(process.cwd());
//=> '/Users/sindresorhus/unicorn'

const foo = reqCwd('./foo');

API

reqCwd(moduleId)

Like require(), throws when the module can't be found.

reqCwd.silent(moduleId)

Returns null instead of throwing when the module can't be found.

moduleId

Type: string

What you would use in require().

Related

  • req-from - Require a module from a given path
  • resolve-from - Resolve the path of a module from a given path
  • resolve-cwd - Resolve the path of a module from the current working directory
  • resolve-pkg - Resolve the path of a package regardless of it having an entry point
  • lazy-req - Require modules lazily

License

MIT © Sindre Sorhus

Current Tags

  • 3.0.0                                ...           latest (8 years ago)

4 Versions

  • 3.0.0 [deprecated]           ...           8 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 15
Today 0
This Week 0
This Month 5
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE