{"id":15646411,"url":"https://github.com/martinheidegger/bgbash","last_synced_at":"2026-05-04T12:34:18.437Z","repository":{"id":143856378,"uuid":"180829125","full_name":"martinheidegger/bgbash","owner":"martinheidegger","description":"Running a background bash to reduce the amount of child processes.","archived":false,"fork":false,"pushed_at":"2020-07-13T22:11:40.000Z","size":34,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-04T15:10:27.011Z","etag":null,"topics":["bash","child-process","nodejs"],"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/martinheidegger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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":"2019-04-11T16:08:29.000Z","updated_at":"2019-05-30T08:02:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"b05d8d57-5c52-4100-bd66-9a8f11f215c1","html_url":"https://github.com/martinheidegger/bgbash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/martinheidegger/bgbash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fbgbash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fbgbash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fbgbash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fbgbash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinheidegger","download_url":"https://codeload.github.com/martinheidegger/bgbash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fbgbash/sbom","scorecard":{"id":621655,"data":{"date":"2025-08-11","repo":{"name":"github.com/martinheidegger/bgbash","commit":"b24adc4c594ee5e61cd01e4222a70a6a529c90af"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-21T05:21:29.398Z","repository_id":143856378,"created_at":"2025-08-21T05:21:29.398Z","updated_at":"2025-08-21T05:21:29.398Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32607660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"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":["bash","child-process","nodejs"],"created_at":"2024-10-03T12:12:47.424Z","updated_at":"2026-05-04T12:34:18.400Z","avatar_url":"https://github.com/martinheidegger.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bgbash\n\n[![Build Status](https://travis-ci.org/martinheidegger/bgbash.svg?branch=master)](https://travis-ci.org/martinheidegger/bgbash)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Maintainability](https://api.codeclimate.com/v1/badges/c1234051f29f448e3a40/maintainability)](https://codeclimate.com/github/martinheidegger/bgbash/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/c1234051f29f448e3a40/test_coverage)](https://codeclimate.com/github/martinheidegger/bgbash/test_coverage)\n\n`bgbash` is a partial drop-in replacement for [`require('child_process').exec`][exec] specifically made for long-running applications.\n\n`npm i bgbash --save`\n\n[exec]: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback\n\n## Why?\n\nStarting a child process using `spawn` or `exec` will create a new instance of `ChildProcess`, open several streams and create a new system background process. This is very expensive if you do it often. `bgbash` starts a single background process on the the first request, every future request will use that process's `stdin` to execute commands. Reducing the startup and feedback time for subsequent calls.\n\n### Performance comparison\n\n| \"echo hi\" - 2000 runs on node-v10.12.0(darwin) | node.js | bgback | notes |\n|-----------------|---------|--------|---|\n| startup         | 10.98ms | 16.05ms | 46% slower - The startup is naturally slower as it does a little more. |\n| repeat response | 4.91ms | 1.96ms | 251% faster - But repeat calls are significantly faster, |\n| repeat user     | 1.31ms | 0.95ms | 137% faster - with part of it coming from the reduced user execution time ... |\n| repeat system   | 0.64ms | 0.04ms | 1457% faster - ... and a significantly reduced system execution time. |\n| rss             | 37.9Mb (avg. 19.8Mb) | 9.9Mb (avg. 6.6Mb) | With a significantly lower rss memory allocation (which is stable even with more calls)  |\n| heap total      | 37.5Mb (avg. 21.4Mb) | 6Mb (avg. 3.2Mb) | The node.js version also fills up the heap a lot quicker to a avg. 32Mb use at 10000 execs while the bgback version needs around 20000 to get there. |\n| heap used       | 19.5Mb (avg. 6.3Mb) | 4.1Mb (avg. 1.4Mb) | The difference in size can be attributed to the additional code loaded.  This will slightly grow with number of calls (~20kb per 5000 calls). Reason is unclear but consistent for both the node.js and bgback version. |\n| c-memory inc.   | 8.6Kb (avg. -201b) | 170b (avg. -7.8Kb) | The C++ memory can be negative as some initial c memory is cleared. |\n\n_Note:_ This data is compiled using the [`./perf.js`](./perf.js) script.\n\n## API compatibility\n\nThe API of `exec` is implemented to be a reasonable _(but not feature complete)_ drop-in replacement for node's native `exec`.\n\n```javascript\nconst { exec } = require('bgbash')\n\nconst cmd = 'echo hi'\nconst opts = { // (optional)\n  cwd: '.',             // (optional) Path in which the code is to be executed, defaults to `process.cwd()`.\n  env: { KEY: 'value' } // (optional) Environment variables to be used for the execution.\n  timeout: 100,         // (optional) Time in milliseconds until a timeout appear, defaults to `0` = no timeout.\n  encoding: 'utf8',     // (optional) Encoding to be used, an unknown or `null` encoding returns a Buffer.\n}\n\nexec(cmd, opts, (error, stdout, stderr) =\u003e {\n  error // Error that might occur, i.e. TIMEOUT or of the process died.\n  stdout // Output of the execution\n  stderr // Error of the execution\n})\n```\n\nA notable incompatibility is that `stderr` will be empty, even though output might exist, if no error occurs.\nThis is done for performance reasons.\n\n## Closing at shutdown\n\nThe background process will continue to **run forever**. If you want the process to close, you have to run `close()`.\n\n```javascript\nconst { exec, close } = require('bgbash')\n\nexec('echo hi')\nclose( // Will be executed after the previous command completed!\n  () =\u003e {\n    // All closed!\n  }\n)\n```\n\n## Promises API\n\nMuch like node js, `bgbash` also comes with a Promise API that is available using either `require('bgbash').promises`\nor `require('bgbash/promises')`.\n\n```javascript\nconst { exec } = require('bgbash').promises\nconst opts = { /* Same options as above. */ }\nconst { stdout, stderr } = await exec('echo hi', opts)\n\ntry {\n  await exec('exit 1', opts)\n} catch (error) {\n  // Error that happened.\n}\n```\n\n### License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fbgbash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinheidegger%2Fbgbash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fbgbash/lists"}