You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

4 years ago
  1. # resolve-cwd [![Build Status](https://travis-ci.org/sindresorhus/resolve-cwd.svg?branch=master)](https://travis-ci.org/sindresorhus/resolve-cwd)
  2. > Resolve the path of a module like [`require.resolve()`](https://nodejs.org/api/globals.html#globals_require_resolve) but from the current working directory
  3. ## Install
  4. ```
  5. $ npm install --save resolve-cwd
  6. ```
  7. ## Usage
  8. ```js
  9. const resolveCwd = require('resolve-cwd');
  10. console.log(__dirname);
  11. //=> '/Users/sindresorhus/rainbow'
  12. console.log(process.cwd());
  13. //=> '/Users/sindresorhus/unicorn'
  14. resolveCwd('./foo');
  15. //=> '/Users/sindresorhus/unicorn/foo.js'
  16. ```
  17. ## API
  18. ### resolveCwd(moduleId)
  19. Like `require()`, throws when the module can't be found.
  20. ### resolveCwd.silent(moduleId)
  21. Returns `null` instead of throwing when the module can't be found.
  22. #### moduleId
  23. Type: `string`
  24. What you would use in `require()`.
  25. ## Related
  26. - [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path
  27. - [req-from](https://github.com/sindresorhus/req-from) - Require a module from a given path
  28. - [req-cwd](https://github.com/sindresorhus/req-cwd) - Require a module from the current working directory
  29. - [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
  30. - [lazy-req](https://github.com/sindresorhus/lazy-req) - Require modules lazily
  31. ## License
  32. MIT © [Sindre Sorhus](https://sindresorhus.com)