Socket
Socket
Sign inDemoInstall

req-from

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    req-from

Require a module like `require()` but from a given path


Version published
Maintainers
1
Install size
9.79 kB
Created

Readme

Source

req-from Build Status

Require a module like require() but from a given path

Install

$ npm install --save req-from

Usage

const reqFrom = require('req-from');

// There is a file at `./foo/bar.js`

reqFrom('foo', './bar');

API

reqFrom(fromDir, moduleId)

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

reqFrom.silent(fromDir, moduleId)

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

fromDir

Type: string

Directory to require from.

moduleId

Type: string

What you would use in require().

Tip

Create a partial using a bound function if you want to require from the same fromDir multiple times:

const reqFromFoo = reqFrom.bind(null, 'foo');

reqFromFoo('./bar');
reqFromFoo('./baz');
  • req-cwd - Require a module from the current working directory
  • 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