Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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 16,810,060 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.