Security News
Internet Archive Hacked, 31 Million Record Compromised
The Internet Archive's "Wayback Machine" has been hacked and defaced, with 31 millions records compromised.
resolve-from
Advanced tools
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.
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');
The 'resolve' package is similar to 'resolve-from' in that it helps to resolve the path of a module. However, 'resolve' provides more options and flexibility, such as the ability to customize the resolution algorithm or to resolve based on the package.json's 'main' field.
The 'enhanced-resolve' package is used by webpack and offers a highly configurable resolution mechanism that can resolve files, directories, and modules. It is more complex and feature-rich compared to 'resolve-from', which is simpler and more straightforward.
The 'browser-resolve' package is designed to resolve modules for browser environments, taking into account the 'browser' field in package.json. It is similar to 'resolve-from' but is specifically tailored for browser-based module resolution.
Resolve the path of a module like
require.resolve()
but from a given path
$ npm install --save resolve-from
var resolveFrom = require('resolve-from');
// there's a file at `./foo/bar.js`
resolveFrom('foo', './bar');
//=> /Users/sindresorhus/dev/test/foo/bar.js
Required
Type: string
The directory to resolve from.
Required
Type: string
What you would use in require()
.
Create a partial using a bound function if you want to require from the same fromDir
multiple times:
var resolveFromFoo = resolveFrom.bind(null, 'foo');
resolveFromFoo('./bar');
resolveFromFoo('./baz');
MIT © Sindre Sorhus
FAQs
Resolve the path of a module like `require.resolve()` but from a given path
The npm package resolve-from receives a total of 78,521,525 weekly downloads. As such, resolve-from popularity was classified as popular.
We found that resolve-from demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
The Internet Archive's "Wayback Machine" has been hacked and defaced, with 31 millions records compromised.
Security News
TC39 is meeting in Tokyo this week and they have approved nearly a dozen proposals to advance to the next stages.
Security News
Our threat research team breaks down two malicious npm packages designed to exploit developer trust, steal your data, and destroy data on your machine.