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
| Name | Type | Description |
|---|---|---|
| file | string | Executable. |
| args | string[] | Arguments. |
| options | object | Limits and process settings. |
| callback | Function | Completion 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());