{"id":22382383,"url":"https://github.com/jcoreio/promisify-child-process","last_synced_at":"2025-04-13T00:44:34.717Z","repository":{"id":39068998,"uuid":"113366277","full_name":"jcoreio/promisify-child-process","owner":"jcoreio","description":"seriously like the best async child process library","archived":false,"fork":false,"pushed_at":"2025-04-11T18:27:49.000Z","size":1267,"stargazers_count":64,"open_issues_count":44,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-13T00:44:30.272Z","etag":null,"topics":["async","async-await","child-process","exec","node","nodejs","promises","spawn"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-06T20:54:14.000Z","updated_at":"2025-01-01T23:34:47.000Z","dependencies_parsed_at":"2023-02-01T09:16:27.500Z","dependency_job_id":"e9948174-041a-4a94-8487-23124b00f56b","html_url":"https://github.com/jcoreio/promisify-child-process","commit_stats":{"total_commits":309,"total_committers":8,"mean_commits":38.625,"dds":"0.35922330097087374","last_synced_commit":"280277f5a39e36c7528a92df755d9a45b18517d5"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fpromisify-child-process","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fpromisify-child-process/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fpromisify-child-process/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fpromisify-child-process/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/promisify-child-process/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650419,"owners_count":21139672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-await","child-process","exec","node","nodejs","promises","spawn"],"created_at":"2024-12-05T00:12:44.981Z","updated_at":"2025-04-13T00:44:34.673Z","avatar_url":"https://github.com/jcoreio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# promisify-child-process\n\n[![CircleCI](https://circleci.com/gh/jcoreio/promisify-child-process.svg?style=svg)](https://circleci.com/gh/jcoreio/promisify-child-process)\n[![Coverage Status](https://codecov.io/gh/jcoreio/promisify-child-process/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/promisify-child-process)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/promisify-child-process.svg)](https://badge.fury.io/js/promisify-child-process)\n\nseriously like the best async child process library\n\n(I'm joking, you may want to use [`execa`](https://github.com/sindresorhus/execa) which has a lot more features.  The minor advantages of this package are,\nit's a dual CJS/ESM package, and it provides wrappers for all the async `child_process` functions.)\n\nBased upon [`child-process-async`](https://github.com/itsjustcon/node-child-process-async),\nbut more thorough, because that package doesn't seem very actively maintained.\n\n`promisify-child-process` provides a **drop-in replacement** for the\noriginal `child_process` functions, not just duplicate methods that\nreturn a `Promise`. So when you call `exec(...)` we still return a\n`ChildProcess` instance, just with `.then()`, `.catch()`, and `.finally()` added to\nmake it promise-friendly.\n\n## Install and Set-up\n\n```sh\nnpm install --save promisify-child-process\n```\n\nIf you are using a old version of Node without built-in `Promise`s or\n`Object.create`, you will need to use polyfills (e.g. `@babel/polyfill`).\n\n```js\n// OLD:\nconst { exec, spawn, fork, execFile } = require('child_process')\n// NEW:\nconst { exec, spawn, fork, execFile } = require('promisify-child-process')\n```\n\n## Upgrading to v3\n\nYou must now pass `maxBuffer` or `encoding` to `spawn`/`fork` if you want to\ncapture `stdout` or `stderr`.\n\n## Resolution/Rejection\n\nThe child process promise will only resolve if the process exits with a code of 0.\nIf it exits with any other code, is killed by a signal, or emits an `'error'` event,\nthe promise will reject.\n\n## Capturing output\n\n`exec` and `execFile` capture `stdout` and `stderr` by default. But `spawn` and\n`fork` don't capture `stdout` and `stderr` unless you pass an `encoding` or\n`maxBuffer` option:\n\n```js\nconst { spawn } = require('promisify-child-process');\n\nasync function() {\n  // captures output\n  const { stdout, stderr } = await spawn('ls', [ '-al' ], {encoding: 'utf8'});\n  const { stdout, stderr } = await spawn('ls', [ '-al' ], {maxBuffer: 200 * 1024});\n\n  // BUG, DOESN'T CAPTURE OUTPUT:\n  const { stdout, stderr } = await spawn('ls', [ '-al' ]);\n}\n```\n\n## Additional properties on rejection errors\n\nIf the child process promise rejects, the error may have the following additional\nproperties:\n\n- `code` - the process' exit code (if it exited)\n- `signal` - the signal the process was killed with (if it was killed)\n- `stdout` - the captured `stdout` (if output capturing was enabled)\n- `stderr` - the captured `stderr` (if output capturing was enabled)\n\n## Wrapper\n\nIf for any reason you need to wrap a `ChildProcess` you didn't create,\nyou can use the exported `promisifyChildProcess` function:\n\n```js\nconst { promisifyChildProcess } = require('promisify-child-process');\n\nasync function() {\n  const { stdout, stderr } = await promisifyChildProcess(\n    some3rdPartyFunctionThatReturnsChildProcess(),\n    { encoding: 'utf8' }\n  )\n}\n```\n\n## Examples\n\n### `exec()`\n\n```js\nasync function() {\n  const { stdout, stderr } = await exec('ls -al');\n  // OR:\n  const child = exec('ls -al', {});\n  // do whatever you want with `child` here - it's a ChildProcess instance just\n  // with promise-friendly `.then()` \u0026 `.catch()` functions added to it!\n  child.stdin.write(...);\n  child.stdout.pipe(...);\n  child.stderr.on('data', (data) =\u003e ...);\n  const { stdout, stderr } = await child;\n}\n```\n\n### `spawn()`\n\n```js\nasync function() {\n  const { stdout, stderr, code } = await spawn('ls', [ '-al' ], {encoding: 'utf8'});\n  // OR:\n  const child = spawn('ls', [ '-al' ], {});\n  // do whatever you want with `child` here - it's a ChildProcess instance just\n  // with promise-friendly `.then()` \u0026 `.catch()` functions added to it!\n  child.stdin.write(...);\n  child.stdout.pipe(...);\n  child.stderr.on('data', (data) =\u003e ...);\n  const { stdout, stderr, code } = await child;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fpromisify-child-process","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Fpromisify-child-process","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fpromisify-child-process/lists"}