e0e895a3a86674d7e43c88942ebe66c56b765d3dcc62d3763127c49775f1f8f4f0b0ad684c582b0af3688631ea235bcf469d4b8fb6de84c39f89a127f341c6 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # resolve-from [![Build Status](https://travis-ci.org/sindresorhus/resolve-from.svg?branch=master)](https://travis-ci.org/sindresorhus/resolve-from)
  2. > Resolve the path of a module like [`require.resolve()`](https://nodejs.org/api/globals.html#globals_require_resolve) but from a given path
  3. ## Install
  4. ```
  5. $ npm install --save resolve-from
  6. ```
  7. ## Usage
  8. ```js
  9. const resolveFrom = require('resolve-from');
  10. // There is a file at `./foo/bar.js`
  11. resolveFrom('foo', './bar');
  12. //=> '/Users/sindresorhus/dev/test/foo/bar.js'
  13. ```
  14. ## API
  15. ### resolveFrom(fromDir, moduleId)
  16. Like `require()`, throws when the module can't be found.
  17. ### resolveFrom.silent(fromDir, moduleId)
  18. Returns `null` instead of throwing when the module can't be found.
  19. #### fromDir
  20. Type: `string`
  21. Directory to resolve from.
  22. #### moduleId
  23. Type: `string`
  24. What you would use in `require()`.
  25. ## Tip
  26. Create a partial using a bound function if you want to resolve from the same `fromDir` multiple times:
  27. ```js
  28. const resolveFromFoo = resolveFrom.bind(null, 'foo');
  29. resolveFromFoo('./bar');
  30. resolveFromFoo('./baz');
  31. ```
  32. ## Related
  33. - [resolve-cwd](https://github.com/sindresorhus/resolve-cwd) - Resolve the path of a module from the current working directory
  34. - [req-from](https://github.com/sindresorhus/req-from) - Require a module from a given path
  35. - [req-cwd](https://github.com/sindresorhus/req-cwd) - Require a module from the current working directory
  36. - [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
  37. - [lazy-req](https://github.com/sindresorhus/lazy-req) - Require modules lazily
  38. ## License
  39. MIT © [Sindre Sorhus](https://sindresorhus.com)