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
Maintainers
1
Install size
6.72 kB
Created

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 resolve-from

Usage

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

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

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

API

resolveFrom(fromDirectory, moduleId)

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

resolveFrom.silent(fromDirectory, moduleId)

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

fromDirectory

Type: string

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 resolve from the same fromDirectory multiple times:

const resolveFromFoo = resolveFrom.bind(null, 'foo');

resolveFromFoo('./bar');
resolveFromFoo('./baz');
  • resolve-cwd - Resolve the path of a module from the current working directory
  • import-from - Import a module from a given path
  • import-cwd - Import a module from the current working directory
  • resolve-pkg - Resolve the path of a package regardless of it having an entry point
  • import-lazy - Import a module lazily
  • resolve-global - Resolve the path of a globally installed module

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 15 Apr 2019

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