UNPKG

1.42 kBMarkdownView Raw
1# `create-require`
2
3[![npm version][npm-version-src]][npm-version-href]
4[![npm downloads][npm-downloads-src]][npm-downloads-href]
5[![Github Actions][github-actions-src]][github-actions-href]
6[![Codecov][codecov-src]][codecov-href]
7
8Polyfill for Node.js [`module.createRequire`](https://nodejs.org/api/modules.html#modules_module_createrequire_filename) (<= v12.2.0)
9
10## Install
11
12```sh
13yarn add create-require
14
15npm install create-require
16```
17
18## Usage
19
20```ts
21function createRequire (filename: string | URL): NodeRequire;
22```
23
24```js
25const createRequire = require('create-require')
26
27const myRequire = createRequire('path/to/test.js')
28const myModule = myRequire('./test-sibling-module')
29```
30
31## License
32
33[MIT](./LICENSE)
34
35<!-- Badges -->
36[npm-version-src]: https://img.shields.io/npm/v/create-require?style=flat-square
37[npm-version-href]: https://npmjs.com/package/create-require
38
39[npm-downloads-src]: https://img.shields.io/npm/dm/create-require?style=flat-square
40[npm-downloads-href]: https://npmjs.com/package/create-require
41
42[github-actions-src]: https://img.shields.io/github/workflow/status/nuxt-contrib/create-require/test/master?style=flat-square
43[github-actions-href]: https://github.com/nuxt-contrib/create-require/actions?query=workflow%3Atest
44
45[codecov-src]: https://img.shields.io/codecov/c/gh/nuxt-contrib/create-require/master?style=flat-square
46[codecov-href]: https://codecov.io/gh/nuxt-contrib/create-require