cross-spawn
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
path-key | 3.1.1 | 2.21 kB | MIT | prod | |
shebang-command | 2.0.0 | 1.47 kB | MIT | prod | |
which | 2.0.2 | 4.39 kB | ISC | prod |
Cross-spawn is a Node.js package providing a cross-platform solution to Node's built-in spawn and spawnSync functions. It addresses several issues present when using spawn on Windows, such as ignoring PATHEXT, lack of shebang support, and issues with commands having spaces, among others. Cross-spawn handles these problems correctly, making it a useful module for developers looking to run child processes across different operating systems.
To use cross-spawn, developers can install it using npm with the command $ npm install cross-spawn
. For Node.js versions 7 and below, use $ npm install cross-spawn@6
. Once installed, the module can be required in a JavaScript file and used just like Node's regular spawn
and spawnSync
. Below is an example:
const spawn = require('cross-spawn');
// Spawn NPM asynchronously
const child = spawn('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });
// Spawn NPM synchronously
const result = spawn.sync('npm', ['list', '-g', '-depth', '0'], { stdio: 'inherit' });
In this example, NPM is spawned asynchronously first, then synchronously. Both invocations use 'npm' as the command, followed by a list of arguments, and configuration options.
Detailed documentation for cross-spawn can be found in its README file on its GitHub repository, located at git+ssh://git@github.com/moxystudio/node-cross-spawn.git
. The README contains information on why developers might use cross-spawn, usage instructions, and notes on certain caveats related to using this module.