
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
create-require
Advanced tools
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.
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');
Similar to create-require, import-fresh allows you to require a module afresh, ensuring that it is re-evaluated. It's useful for testing and situations where you need to bypass Node's require cache. However, it doesn't allow specifying a directory for module resolution like create-require does.
Proxyquire is designed for overriding dependencies during testing. It allows you to create a custom `require` function that can return mock modules instead of the real ones. While it serves a different primary purpose (mocking for tests), it shares the concept of creating a custom require function with create-require.
create-require
Polyfill for Node.js module.createRequire
(<= v12.2.0)
yarn add create-require
npm install create-require
function createRequire (filename: string | URL): NodeRequire;
const createRequire = require('create-require')
const myRequire = createRequire('path/to/test.js')
const myModule = myRequire('./test-sibling-module')
FAQs
Polyfill for Node.js module.createRequire (<= v12.2.0)
The npm package create-require receives a total of 17,895,333 weekly downloads. As such, create-require popularity was classified as popular.
We found that create-require demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.