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 fileTake it
Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 1–10why, one step back1<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 directory10Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 11why, one step back11The [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 back1213```js14import {execa} from 'execa';1516await execa({cwd: '/path/to/cwd'})`npm run build`;17```18Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 19why, one step back19And be retrieved with the [`result.cwd`](api.md#resultcwd) property.Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 20–28why, one step back2021```js22const {cwd} = await execa`npm run build`;23```2425## Local binaries2627Package managers like `npm` install local binaries in `./node_modules/.bin`.28Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 29why, one step back29```shAdd user guides (#989)ehmickybefore adoptionbe91ecf
lines 30–36why, one step back30$ npm install -D eslint31```3233```js34await execa('./node_modules/.bin/eslint');35```36Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 37why, one step back37The [`preferLocal`](api.md#optionspreferlocal) option can be used to execute those local binaries.Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 38–39why, one step back3839```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
line 40why, one step back40await execa({preferLocal: true})`eslint`;Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 41–42why, one step back41```42Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 43why, one step back43Those 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 back4445```jsImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
line 46why, one step back46await execa({preferLocal: true, localDir: '/path/to/dir'})`eslint`;Add user guides (#989)ehmickybefore adoptionbe91ecf
lines 47–62why, one step back47```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 subprocess62Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 63why, one step back63When 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 back6465Specific 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)