{"id":23128257,"url":"https://github.com/victorqueiroz/child-process-utilities","last_synced_at":"2026-04-24T20:07:31.239Z","repository":{"id":168073410,"uuid":"643694166","full_name":"VictorQueiroz/child-process-utilities","owner":"VictorQueiroz","description":"Wrapper for the Node.js child_process native module.","archived":false,"fork":false,"pushed_at":"2025-01-02T08:20:38.000Z","size":332,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-07T16:05:14.007Z","etag":null,"topics":["child-process","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VictorQueiroz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2023-05-22T00:33:34.000Z","updated_at":"2025-01-02T08:20:41.000Z","dependencies_parsed_at":"2024-09-18T05:44:04.835Z","dependency_job_id":"37f9e4bc-c368-4776-9872-4d5ad1d373ac","html_url":"https://github.com/VictorQueiroz/child-process-utilities","commit_stats":null,"previous_names":["victorqueiroz/child-process-utilities"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/VictorQueiroz/child-process-utilities","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorQueiroz%2Fchild-process-utilities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorQueiroz%2Fchild-process-utilities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorQueiroz%2Fchild-process-utilities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorQueiroz%2Fchild-process-utilities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VictorQueiroz","download_url":"https://codeload.github.com/VictorQueiroz/child-process-utilities/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorQueiroz%2Fchild-process-utilities/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32238799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["child-process","nodejs"],"created_at":"2024-12-17T09:17:53.678Z","updated_at":"2026-04-24T20:07:31.213Z","avatar_url":"https://github.com/VictorQueiroz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# child-process-utilities\n\nMemory-efficient utilities to deal with `child_process` native Node.js package.\n\n## Installation\n\n```\nnpm i child-process-utilities\n```\n\n## Usage\n\n### Iterate over the output streams of a process using async iterators\n\nThis method does not use any sort of buffering. Which means that we do not cache the entire output into memory.\n\n#### `stdout`/`stderr`\n\nThe values returned by `stdout` and `stderr` can be iterated directly by default.\n\n```ts\nimport { spawn } from \"child-process-utilities\";\n\nconst childProcess = spawn(/* ... */, /* ... */, /* ... */);\n\nfor await (const chunk of childProcess.output().stdout()) {\n  //             ^ Uint8Array\n  console.log(\"Chunk: %s\", chunk);\n}\n```\n\n#### `split`\n\nIn the example below, the output is streamed line by line, since we're using the `\\n` character, but any other character can be passed to `split`.\n\n```ts\nimport { spawn } from \"child-process-utilities\";\n\nconst lines = spawn\n  .pipe(bin.curl, [\"-L\", project.license.url])\n  .output()\n  .stdout()\n  .split(\"\\n\"); // Returns an AsyncIterableIterator\u003cstring\u003e\nfor await (const line of lines) {\n  console.log(\"This is a line: %s\", line);\n}\n\n// Or\nconst chunks = spawn\n  .pipe(bin.curl, [\"-L\", project.license.url])\n  .output()\n  .stdout(); // `IReadable` is an async iterator by itself\nfor await (const chunk of chunks) {\n  //             ^ Uint8Array\n  console.log(\"Chunk: %s\", line);\n}\n```\n\n**Please note that for performance reasons any decisive output functions can only be called once.**\n\n```ts\nconst childProcess = spawn(/* ... */, /* ... */, /* ... */);\n\nchildProcess.output().stderr().raw() // Do\nchildProcess.output().stderr().raw() // Don't\n//             stderr ^^^^^^\n\n// stdout\nchildProcess.output().stdout().raw() // Do\nchildProcess.output().stdout().raw() // Don't\n//             stdout ^^^^^^\n```\n\n### Wait for a process to finish\n\n```ts\nimport { spawn } from \"child-process-utilities\";\n\nexport default async function () {\n  await spawn(\"npx\", [\"ts-node\", \"src\"]).wait();\n}\n```\n\n### Wait for a process to finish without consuming stdout\n\n```ts\nimport { spawn } from \"child-process-utilities\";\n\nexport default async function () {\n  await spawn.pipe(\"npx\", [\"ts-node\", \"src\"]).wait();\n}\n```\n\n### Get the output of a process\n\n#### [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)\n\n```ts\nimport { spawn } from \"child-process-utilities\";\n\nexport default async function () {\n  const { stdout, stderr } = await spawn(\"npx\", [\"ts-node\", \"src\"]).output();\n  console.log(await stdout().decode(\"UTF-8\")); // Returns a string\n  console.error(await stderr().decode(\"UTF-8\")); // Returns a string\n}\n```\n\n#### [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)\n\n```ts\nimport { spawn } from \"child-process-utilities\";\n\nexport default async function () {\n  const { stdout, stderr } = await spawn(\"npx\", [\"ts-node\", \"src\"]).output();\n  console.log(await stdout().raw()); // Returns an Uint8Array\n  console.error(await stderr().raw()); // Returns an Uint8Array\n}\n```\n\n#### [JSON](https://www.json.org/json-en.html)\n\n```ts\nimport { spawn } from \"child-process-utilities\";\n\nexport default async function () {\n  const { stdout, stderr } = await spawn(\"npx\", [\"ts-node\", \"src\"]).output();\n  console.log(await stdout().json()); // Parses the stdout as JSON\n  console.error(await stderr().json()); // Parses the stderr as JSON\n}\n```\n\n##### JSON property type inference\n\nYou can pass a type to the `spawn` function to infer the return type of the `output` method. Currently, we only support defining a type for the `json` `output` property.\n\n```ts\n// (method) IReadable\u003c{ json: number; }\u003e.json\u003cnumber\u003e(): Promise\u003cnumber\u003e\nspawn\u003c/* Using TypeScript inline types */ { json: number }\u003e(\"x\")\n  .output()\n  .stdout()\n  .json(); // Promise\u003cnumber\u003e\n\ninterface IVideoMetadata {\n  duration: number;\n  fileName: string;\n}\n\ninterface IGetVideoMetadataTypes {\n  json: IVideoMetadata;\n}\n\n// (method) IReadable\u003cIVideoMetadata\u003e.json\u003cIVideoMetadata\u003e(): Promise\u003cIVideoMetadata\u003e\nspawn\u003cIGetVideoMetadataTypes\u003e(\"/home/user/get-video-metadata.sh\", [\n  \"video.mp4\" /* ... */\n])\n  .output()\n  .stdout()\n  .json(); // Promise\u003cIVideoMetadata\u003e\n\n// (method) IReadable\u003c{ json: unknown; }\u003e.json\u003cunknown\u003e(): Promise\u003cunknown\u003e\nspawn(\"x\").output().stdout().json(); // Promise\u003cunknown\u003e\n```\n\nAdvantages on this approach is that you can define a spawn method that returns a predefined type:\n\n```ts\nimport { spawn } from \"child-process-utilities\";\n\nexport interface IVideoMetadata {\n  duration: number;\n  fileName: string;\n}\n\nexport interface IGetVideoMetadataTypes {\n  json: IVideoMetadata;\n}\n\nconst getVideoMetadata = (url: string) =\u003e\n  spawn\u003cIGetVideoMetadataTypes\u003e(\"/home/user/get-video-metadata.sh\", [url]);\n\nexport default getVideoMetadata;\n```\n\n```ts\nimport getVideoMetadata from \"./getVideoMetadata\";\n\nexport default async function askForVideoMetadata() {\n  const pendingVideoMetadata = getVideoMetadata(\"video.mp4\");\n  const error = await pendingVideoMetadata.output().stderr().raw();\n\n  try {\n    const videoMetadata = await pendingVideoMetadata.output().stdout().json();\n  } catch (error) {\n    process.stderr.write(error);\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorqueiroz%2Fchild-process-utilities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictorqueiroz%2Fchild-process-utilities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictorqueiroz%2Fchild-process-utilities/lists"}