A cross-platform solution to Node.js spawn and spawnSync that fixes Windows-specific issues.
cross-spawn is a Node.js package that provides a cross-platform implementation of Node's `spawn` and `spawnSync` methods. It solves numerous Windows-specific issues with Node's native child process execution, including problems with PATHEXT, shebangs, command paths with spaces, and argument escaping. The module serves as a drop-in replacement that ensures consistent behavior across different operating systems.
Node.js developers building CLI tools, build scripts, or applications that need to execute shell commands across multiple platforms, particularly those who need reliable Windows compatibility.
Developers choose cross-spawn because it provides a battle-tested solution to Node's platform-specific spawn issues without changing the API. Unlike alternatives, it handles edge cases like command shims and complex argument escaping correctly, making it the most reliable option for cross-platform command execution.
A cross platform solution to node's spawn and spawnSync
Fixes Windows-specific issues like PATHEXT handling, shebangs, and command paths with spaces, ensuring consistent behavior across operating systems as detailed in the 'Why' section.
Uses the same API as Node's native spawn and spawnSync, making integration seamless without requiring code changes, as emphasized in the 'Usage' section.
Properly escapes shell arguments to prevent syntax errors with quotes and parentheses, addressing a key problem with command shims highlighted in the README.
Correctly executes command shims from node_modules/.bin/ with complex arguments, solving invalid syntax errors that occur in native spawn, as shown in test examples.
On Windows, shebang support is restricted to basic #!/usr/bin/env <program> without arguments, which may not cover all use cases, as admitted in the 'Shebangs support' caveat.
When using options.shell, cross-spawn's enhancements are disabled, mimicking Node's behavior and reducing its value in those scenarios, as warned in the 'Caveats' section.
Its primary benefits address Windows issues, so on Unix systems, it adds dependency overhead without significant advantage, making it less optimal for platform-specific development.
:shell: Portable Unix shell commands for Node.js
Process execution for humans
Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Access the system clipboard (copy/paste)
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.