Skip to content
Myr

environment.md

This file

Path

docs/environment.md

75 lines · 2.1 KiB · Markdown

Last changed by

Improve `readme.md` (#999)ehmickybefore adoptionaca3db3

History of this file

Take it

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 1–10why, one step back
1<picture>
2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# 🌐 Environment89## Current directory10

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 11why, one step back
11The [current directory](https://en.wikipedia.org/wiki/Working_directory) when running the command can be set with the [`cwd`](api.md#optionscwd) option.

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 12–18why, one step back
12
13```js14import {execa} from 'execa';1516await execa({cwd: '/path/to/cwd'})`npm run build`;17```18

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 19why, one step back
19And be retrieved with the [`result.cwd`](api.md#resultcwd) property.

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 20–28why, one step back
20
21```js22const {cwd} = await execa`npm run build`;23```2425## Local binaries2627Package managers like `npm` install local binaries in `./node_modules/.bin`.28

Improve `readme.md` (#999)ehmickybefore adoptionaca3db3

line 29why, one step back
29```sh

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 30–36why, one step back
30$ npm install -D eslint
31```3233```js34await execa('./node_modules/.bin/eslint');35```36

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 37why, one step back
37The [`preferLocal`](api.md#optionspreferlocal) option can be used to execute those local binaries.

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 38–39why, one step back
38
39```js

Improve `readme.md` (#999)ehmickybefore adoptionaca3db3

line 40why, one step back
40await execa({preferLocal: true})`eslint`;

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 41–42why, one step back
41```
42

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 43why, one step back
43Those are searched in the current or any parent directory. The [`localDir`](api.md#optionslocaldir) option can select a different directory.

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 44–45why, one step back
44
45```js

Improve `readme.md` (#999)ehmickybefore adoptionaca3db3

line 46why, one step back
46await execa({preferLocal: true, localDir: '/path/to/dir'})`eslint`;

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 47–62why, one step back
47```
4849## Current package's binary5051Execa can be combined with [`get-bin-path`](https://github.com/ehmicky/get-bin-path) to test the current package's binary. As opposed to hard-coding the path to the binary, this validates that the `package.json` [`bin`](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin) field is correctly set up.5253```js54import {execa} from 'execa';55import {getBinPath} from 'get-bin-path';5657const binPath = await getBinPath();58await execa(binPath);59```6061## Background subprocess62

Move API reference to its own page (#996)ehmickybefore adoption7cde496

line 63why, one step back
63When the [`detached`](api.md#optionsdetached) option is `true`, the subprocess [runs independently](https://en.wikipedia.org/wiki/Background_process) from the current process.

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 64–75why, one step back
64
65Specific behavior depends on the platform. [More info.](https://nodejs.org/api/child_process.html#child_process_options_detached)6667```js68await execa({detached: true})`npm run start`;69```7071<hr>7273[**Next**: ❌ Errors](errors.md)\74[**Previous**: 🐢 Node.js files](node.md)\75[**Top**: Table of contents](../readme.md#documentation)