Child process

child_process.execFile()

Runs an executable directly by default and buffers its output. Use explicit output and time limits for bounded tasks; use spawn for streaming large results. Tested on Node.js 22.16.0. Example output (one line per entry): ["42"].

Formal Syntax & Structure

nodejs syntaxnodejs
execFile(file[, args][, options][, callback])

Parameters & Attributes

NameTypeDescription
filestringExecutable.
argsstring[]Arguments.
optionsobjectLimits and process settings.
callbackFunctionCompletion callback.

Return Value

ChildProcess

Subprocess handle.

Working Example

Example Snippetnodejs
import { execFile } from 'node:child_process';import { promisify } from 'node:util';const { stdout } = await promisify(execFile)(process.execPath, ['-e', 'console.log(21*2)'], { timeout: 1000, maxBuffer: 1024, env: {} });console.log(stdout.trim());
Node.js Reference