The `eval` package for Node.js provides a mechanism to evaluate JavaScript code strings as if they were standalone modules loaded via `require()`, but without necessitating a file path. It leverages Node.js's built-in `vm` module to create a sandboxed environment for execution. This allows developers to programmatically load and execute module content from non-standard locations or inject custom contexts and scopes into the evaluated code. A key feature is the ability to control access to global variables, including `require()` itself, through an `includeGlobals` option. The package is currently at version 0.1.8, indicating a very mature or, more likely, an inactive development status. Its release cadence is effectively dormant. It differentiates itself from a simple `eval()` by mimicking Node's module loading environment, making it suitable for scenarios requiring dynamic module-like code execution within a controlled environment.
npm install evalVerified import paths — ran on the pinned version, not inferred.
Demonstrates evaluating JavaScript code strings as modules, including exporting values, functions, accessing Node.js globals, and providing custom scopes.
Consider migrating to more actively maintained packages or Node.js's native `vm` module if sandboxing is required.
Only set `includeGlobals` to `true` when evaluating trusted code. Carefully review the implications of exposing globals to untrusted content.
Thoroughly test `eval`'s behavior across all target Node.js versions. For critical applications, consider directly using the Node.js `vm` module for finer control and up-to-date behavior.
Pass `true` as the `includeGlobals` argument (the fourth parameter) to the `_eval` function: `_eval(content, filename, scope, true)`.
This package is CommonJS-only. Use `const _eval = require('eval')` to correctly import the function.No dependency data recorded yet.