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.
import-from
Advanced tools
The npm package 'import-from' allows you to import modules from a specific path, bypassing the default behavior of Node.js module resolution. This can be particularly useful in scenarios where you need to dynamically choose different versions of a module or when working with plugins that may not be in the node_modules directory of the current project.
Import module from a specific directory
This feature allows you to import a module by specifying the directory from which the module should be loaded. This is useful for loading modules dynamically based on runtime conditions or configurations.
const importFrom = require('import-from');
const specificModule = importFrom('/path/to/specific/directory', 'module-name');
Silent import attempt
This feature provides a way to attempt to import a module silently without throwing errors if the module does not exist. It is useful for optional dependencies that may or may not be present in a given environment.
const importFrom = require('import-from');
const tryImport = importFrom.silent('/path/to/directory', 'optional-module');
This package allows you to require modules from a string of code. It is similar to 'import-from' in that it modifies the standard module loading behavior, but it focuses on executing and importing code from strings rather than from specific file paths.
Proxyquire is designed to help with mocking dependencies for testing purposes. It allows you to replace modules in require calls within the module under test. While it also changes how modules are loaded, it is specifically tailored for testing rather than general module loading from different locations.
Import a module like with
require()
but from a given path
$ npm install import-from
const importFrom = require('import-from');
// There is a file at `./foo/bar.js`
importFrom('foo', './bar');
Like require()
, throws when the module can't be found.
Returns undefined
instead of throwing when the module can't be found.
Type: string
Directory to import from.
Type: string
What you would use in require()
.
Create a partial using a bound function if you want to import from the same fromDir
multiple times:
const importFromFoo = importFrom.bind(null, 'foo');
importFromFoo('./bar');
importFromFoo('./baz');
FAQs
Import a module like with `require()` but from a given path
The npm package import-from receives a total of 6,014,537 weekly downloads. As such, import-from popularity was classified as popular.
We found that import-from 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.