Socket
Socket
Sign inDemoInstall

resolve-from

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    resolve-from

Resolve the path of a module like require.resolve() but from a given path


Version published
Weekly downloads
82M
increased by1.72%
Maintainers
1
Install size
4.06 kB
Created
Weekly downloads
 

Package description

What is resolve-from?

The resolve-from npm package is a module that allows you to resolve the path of a module like require.resolve() but from a given path. It is useful for situations where you need to resolve modules from a different directory than the current file's directory.

What are resolve-from's main functionalities?

Resolve the path of a module from a given path

This feature allows you to resolve the path of a module from a specific directory. You provide the directory as the first argument and the module name as the second argument. It returns the resolved path to the module.

const resolveFrom = require('resolve-from');
const modulePath = resolveFrom('/some/path', 'some-module');

Silently resolve the path of a module or return null

This feature is similar to the first, but it will return null instead of throwing an error if the module cannot be found. This is useful for cases where you want to check for a module's existence without causing an exception.

const resolveFrom = require('resolve-from');
const modulePath = resolveFrom.silent('/some/path', 'non-existent-module');

Other packages similar to resolve-from

Readme

Source

resolve-from Build Status

Resolve the path of a module like require.resolve() but from a given path

Install

$ npm install --save resolve-from

Usage

const resolveFrom = require('resolve-from');

// there's a file at `./foo/bar.js`

resolveFrom('foo', './bar');
//=> '/Users/sindresorhus/dev/test/foo/bar.js'

API

resolveFrom(fromDir, moduleId)

fromDir

Type: string

The directory to resolve 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 resolveFromFoo = resolveFrom.bind(null, 'foo');

resolveFromFoo('./bar');
resolveFromFoo('./baz');

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 05 Oct 2015

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