Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

req-cwd

sindresorhus611.1kMITdeprecated3.0.0TypeScript support: definitely-typed

Renamed to import-cwd.

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

require, resolve, path, module, from, like, cwd, current, working, directory, import

readme

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().

  • 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