UNPKG

1.62 kBMarkdownView Raw
1# resolve-cwd [![Build Status](https://travis-ci.org/sindresorhus/resolve-cwd.svg?branch=master)](https://travis-ci.org/sindresorhus/resolve-cwd)
2
3> Resolve the path of a module like [`require.resolve()`](https://nodejs.org/api/globals.html#globals_require_resolve) but from the current working directory
4
5
6## Install
7
8```
9$ npm install resolve-cwd
10```
11
12
13## Usage
14
15```js
16const resolveCwd = require('resolve-cwd');
17
18console.log(__dirname);
19//=> '/Users/sindresorhus/rainbow'
20
21console.log(process.cwd());
22//=> '/Users/sindresorhus/unicorn'
23
24console.log(resolveCwd('./foo'));
25//=> '/Users/sindresorhus/unicorn/foo.js'
26```
27
28
29## API
30
31### resolveCwd(moduleId)
32
33Like `require()`, throws when the module can't be found.
34
35### resolveCwd.silent(moduleId)
36
37Returns `undefined` instead of throwing when the module can't be found.
38
39#### moduleId
40
41Type: `string`
42
43What you would use in `require()`.
44
45
46## Related
47
48- [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path
49- [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path
50- [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory
51- [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
52- [import-lazy](https://github.com/sindresorhus/import-lazy) - Import a module lazily
53- [resolve-global](https://github.com/sindresorhus/resolve-global) - Resolve the path of a globally installed module
54
55
56## License
57
58MIT © [Sindre Sorhus](https://sindresorhus.com)