
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
node-file-eval
Advanced tools
Read file and eval it. Uses node-eval.
Like require
, but asynchronous and doesn't use the module cache.
Important: internally node-file-eval
will resolve passed relative paths with path.resolve()
, not require.resolve()
.
$ npm install --save node-file-eval
const nodeFileEval = require('node-file-eval');
fileEval('./path/to/file.js')
.then(console.log)
.catch(console.log);
Type: string
.
The filename or file descriptor.
The node-file-eval
determinate format by extension. If filename ends with .json
extention, its contents will be parsing with JSON.parse
. If filename ends with .js
, its contents will be evaluating with vm.
By default expected JS-expression or CommonJS module contents.
Type: Object
, string
.
Options or encoding.
Type: string
.
Default: utf-8
.
The file encoding.
Type: string
.
Default: r
.
The flag mode.
Type: Object
.
The object to provide into execute method.
If context
is specified, then module contents will be evaluating with vm.runInNewContext
.
If context
is not specified, then module contents will be evaluating with vm.runInThisContext
.
With context you can provide some like-a-global variables into node-file-eval
.
const nodeFileEval = require('node-file-eval');
const secretKey = '^___^';
const contents = 'module.exports = secretKey;';
// The file has the contents "module.exports = secretKey;"
nodeFileEval('./path/to/file.js', {
context: { secretKey }
});
// ➜ '^___^'
Synchronous version of nodeFileEval.
Method signature is same.
Supports CommonJS and JSON formats.
See examples with evaluating files with different formats.
Evaluates CommonJS
files with .js
extention.
const nodeFileEval = require('node-file-eval');
// export data with `module.exports` or `exports`
nodeFileEval('./path/to/file.js');
Evaluates JSON
files with .json
extention.
const nodeFileEval = require('node-file-eval');
nodeFileEval('./path/to/file.json');
MIT © Andrew Abramov
FAQs
Read node.js file and eval it
The npm package node-file-eval receives a total of 107 weekly downloads. As such, node-file-eval popularity was classified as not popular.
We found that node-file-eval 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
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.