Socket
Socket
Sign inDemoInstall

create-require

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    create-require

Polyfill for Node.js module.createRequire (<= v12.2.0)


Version published
Weekly downloads
17M
increased by1.15%
Maintainers
1
Created
Weekly downloads
 

Package description

What is create-require?

The create-require npm package is designed to dynamically create a `require` function at a given path. This is particularly useful in scenarios where you need to resolve modules or require files relative to a specific directory, rather than the current working directory of the process. It can be used to simulate the behavior of Node.js's `require` in different contexts or to dynamically load modules from various locations in a filesystem.

What are create-require's main functionalities?

Creating a custom require function for a specific directory

This feature allows you to create a new `require` function that resolves modules as if it was called from the specified directory. This is useful for loading modules from a directory different from the current script's directory.

const createRequire = require('create-require');
const myRequire = createRequire('/path/to/my/directory');
const myModule = myRequire('./myModule');

Other packages similar to create-require

Changelog

Source

1.0.2 (2020-06-12)

Bug Fixes

  • use fake path if filename is directory (c8e0983)

Readme

Source

create-require

npm version npm downloads Github Actions Codecov

Polyfill for Node.js module.createRequire (<= v12.2.0)

Install

yarn add create-require

npm install create-require

Usage

function createRequire (filename: string | URL): NodeRequire;
const createRequire = require('create-require')

const myRequire = createRequire('path/to/test.js')
const myModule = myRequire('./test-sibling-module')

License

MIT

FAQs

Last updated on 12 Jun 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc