Skip to content
Myr

environment.md

This file

Path

docs/environment.md

75 lines · 2.1 KiB · Markdown

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 1–75why, 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 directory1011The [current directory](https://en.wikipedia.org/wiki/Working_directory) when running the command can be set with the [`cwd`](api.md#optionscwd) option.1213```js14import {execa} from 'execa';1516await execa({cwd: '/path/to/cwd'})`npm run build`;17```1819And be retrieved with the [`result.cwd`](api.md#resultcwd) property.2021```js22const {cwd} = await execa`npm run build`;23```2425## Local binaries2627Package managers like `npm` install local binaries in `./node_modules/.bin`.2829```sh30$ npm install -D eslint31```3233```js34await execa('./node_modules/.bin/eslint');35```3637The [`preferLocal`](api.md#optionspreferlocal) option can be used to execute those local binaries.3839```js40await execa({preferLocal: true})`eslint`;41```4243Those are searched in the current or any parent directory. The [`localDir`](api.md#optionslocaldir) option can select a different directory.4445```js46await execa({preferLocal: true, localDir: '/path/to/dir'})`eslint`;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 subprocess6263When the [`detached`](api.md#optionsdetached) option is `true`, the subprocess [runs independently](https://en.wikipedia.org/wiki/Background_process) from the current process.6465Specific 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)