Socket
Socket
Sign inDemoInstall

req-cwd

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    req-cwd

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


Version published
Maintainers
1
Install size
14.1 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 08 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc