Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
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 5,517,994 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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.