Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
import-from-string
Advanced tools
Load module from string using require or import.
import.meta.url
npm install import-from-string
import { importFromString, requireFromString } from "import-from-string";
const cjs = requireFromString("module.exports = 'Hi World!'");
console.log(cjs); // Hi World!
const esm = await importFromString("export default 'Hello World!'");
console.log(esm.default); // Hello World!
const { requireFromString, importFromString } = require("import-from-string");
async function main() {
const cjs = requireFromString("module.exports = 'Hi World!'");
console.log(cjs); // Hi World!
const esm = await importFromString("export default 'Hello World!'");
console.log(esm.default); // Hello World!
}
main();
Type: string
The code to import.
Type: string
Default: {Date.now()}.js
The virtual file name of the code to import.
Type: string
Default: The directory where the function is called
The virtual directory to import the code into.
Type: TransformOptions
esbuild transform options.
Type: BuildOptions
esbuild options.
Type: boolean
Default: false
skip esbuild build.
Type: string
The code to import.
Type: string
Default: {Date.now()}.js
The virtual file name of the code to import.
Type: string
Default: The directory where the function is called
The virtual directory to import the code into.
Type: string[]
Default: []
An array of additional paths to append when resolving modules.
Type: string[]
Default: []
An array of additional paths to prepend when resolving modules.
MIT License © 2023-Present Condor Hero
FAQs
Load module from string using require or import.
We found that import-from-string demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.