Skip to content
Myr

node.md

This file

Path

docs/node.md

49 lines · 1.6 KiB · Markdown

Last changed by

Not known.

History of this file

Take it

Show the source

node.md

execa logo

🐢 Node.js files

Run Node.js files

import {execaNode, execa} from 'execa';

await execaNode`file.js argument`;
// Is the same as:
await execa({node: true})`file.js argument`;
// Or:
await execa`node file.js argument`;

Node.js CLI flags

When using the node option or execaNode(), the current Node.js CLI flags are inherited. For example, the subprocess will use --allow-fs-read if the current process does.

The nodeOptions option can be used to set different CLI flags.

await execaNode({nodeOptions: ['--allow-fs-write']})`file.js argument`;

Node.js version

The same applies to the Node.js version, which is inherited too.

get-node and the nodePath option can be used to run a specific Node.js version. Alternatively, nvexeca or nve can be used.

import {execaNode} from 'execa';
import getNode from 'get-node';

const {path: nodePath} = await getNode('16.2.0');
await execaNode({nodePath})`file.js argument`;

Next: 🌐 Environment
Previous: 📜 Scripts
Top: Table of contents