{"id":22428411,"url":"https://github.com/momsfriendlydevco/exec","last_synced_at":"2025-07-22T03:31:32.910Z","repository":{"id":78689333,"uuid":"179791169","full_name":"MomsFriendlyDevCo/exec","owner":"MomsFriendlyDevCo","description":"Wrapper around child_process.spawn() / exec() to execute external commands","archived":false,"fork":false,"pushed_at":"2022-11-03T05:05:50.000Z","size":97,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-18T20:20:00.527Z","etag":null,"topics":[],"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/MomsFriendlyDevCo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"zenodo":null}},"created_at":"2019-04-06T05:08:20.000Z","updated_at":"2022-02-18T00:23:32.000Z","dependencies_parsed_at":"2023-03-07T08:15:56.841Z","dependency_job_id":null,"html_url":"https://github.com/MomsFriendlyDevCo/exec","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MomsFriendlyDevCo/exec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MomsFriendlyDevCo","download_url":"https://codeload.github.com/MomsFriendlyDevCo/exec/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2Fexec/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266419435,"owners_count":23925767,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-12-05T20:14:42.854Z","updated_at":"2025-07-22T03:31:32.881Z","avatar_url":"https://github.com/MomsFriendlyDevCo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"@momsfriendlydevco/exec\n=======================\nTiny wrapper around `child_process.spawn()` / `exec()` which provides some additional functionality.\n\n**Differences from spawn / exec**:\n\n* Always returns a promise for running processes. That promise can return output if `buffer` is enabled\n* Can easily prefix output to STDOUT / STDERR or both\n* Can accept a single array of command arguments rather than treating the program + args separately\n* Can accept a single string command which is correctly transformed internally\n* Optionally can buffer and provide all output when resolving / rejecting\n* Supports piping\n* Auto-trimming out output\n* Hashbangs supported\n* Can natively accept JSON and fail if not given valid input\n* Support for aliases within commands (and pipes)\n\n\n```javascript\nvar exec = require('@momsfriendlydevco/exec');\n\nexec('echo \"Hello world\"')\n\t.then(()=\u003e /* ... */)\n\nexec(['docker', 'build', '--tag=momsfriendlydevco/test', '.'], {\n\tprefix: '[docker]',\n})\n\t.then(()=\u003e /* ... */)\n```\n\n\nDebugging\n---------\nThis module uses the [Debug NPM package](https://github.com/visionmedia/debug#readme) and responds to `exec`.\n\nTo see verbose debugging output simply set `DEBUG=exec` or any valid glob expression.\n\n```\n\u003e DEBUG=exec node someNodeFile.js\n```\n\n\nAPI\n===\nThis module exposes a function (which returns a promise) as well as a few utility functions. The function takes an array (or string) of arguments where the executable is the first item within that array. An additional options object can be passed. \n\nexec([cmd], \u003ccmd+args|args\u003e, [options])\n---------------------------------------\n\nSupported options:\n\n| Option               | Type                      | Default                  | Description                                                                                                                                    |\n| ------------------   | ------------------------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |\n| `buffer`             | `boolean`                 | `undefined`              | Set both `bufferStdout` + `bufferStderr` at once                                                                                               |\n| `bufferStdout`       | `boolean`                 | `false`                  | When resolving the promise provide the output from the command as the value of the resolved promise                                            |\n| `bufferStderr`       | `boolean`                 | `false`                  | As with `bufferStdout` but also include STDERR stream data                                                                                     |\n| `log`                | `boolean` or `function`   | `undefined`              | Set both `logStdout` + `logStderr` at once                                                                                                     |\n| `logStdout`          | `boolean` or `function`   | `console.log`            | Logging function to use when outputting STDOUT, set to falsy to disable                                                                        |\n| `logStderr`          | `boolean` or `function`   | `console.log`            | Similar to `logStdout` but with the STDERR stream                                                                                              |\n| `prefix`             | `string` or `function`    | `undefined`              | Sets both `prefixStdout` + `prefixStderr` at once                                                                                              |\n| `prefixStdout`       | `string` or `function`    | `undefined`              | Sets a string prefix for any STDOUT output, if a function it is called as `(msg)` and uses the return value, effectively acting as a wrapper   |\n| `prefixStderr`       | `string` or `function`    | `undefined`              | Similar functionality to `prefixStdout` but with STDERR streams                                                                                |\n| `rejectError`        | `string`, `boolean` or `function` | `'Non-zero exit code'`   | If a string use this to signal errors, boolean `false` returns the error code in the `catch()` block, if a function that function is called as `(code)` to return the string to return |\n| `reformat`           | `boolean`                 | `undefined`              | Set both `reformatStdout` + `reformatStderr` at once                                                                                           |\n| `reformatStdout`     | `boolean`                 | `false`                  | When accepting data from Stdout and `prefixStdout` is enabled, also split newline input so each newline is prefixed                            |\n| `reformatStderr`     | `boolean`                 | `false`                  | As with `reformatStdout` but also reformat STDERR stream data                                                                                  |\n| `resolveCodes`       | `array`                   | `[0]`                    | Array of numeric error codes to accept as a valid response                                                                                     |\n| `json`               | `boolean`                 | `false`                  | Attempt to convert the contents of the output buffer (contents dictated by `buffer*` into JSON before returning), implies `bufferStdout`       |\n| `jsonInvalidTruncate` | `number`                 | `30`                     | When parsing invalid JSON truncate the error output to this many bytes (i.e. not UTF-8 friendly)                                               |\n| `jsonInvalidTruncateSuffix` | `string`           | `\"…\"`                    | Suffix to append when truncating invalid JSON input                                                                                            |\n| `pipe`               | `boolean` or `string`     | `'auto'`                 | Use the shell to execute, if `'auto'` pipes are detected automatically                                                                         |\n| `shell`              | `string`                  | `'/bin/sh'`              | A STDIN processing shell, used when `pipe` is true or auto detected                                                                            |\n| `hashbang`           | `boolean`                 | `true`                   | If specified the file is opened and `hashbangReadLength` bytes examined for a hashbang, if one is found the command is prefixed with it        |\n| `hashbangReadLength` | `number`                  | `100`                    | How many bytes to explore at the start of files for the hashbang                                                                               |\n| `trim`               | `boolean`                 | `true`                   | Automatically trim output to remove trailing newlines and spaces                                                                               |\n| `trimRegExp`         | `RegExp`                  | `/[\\n\\s]+$/m`            | The regular expression used when trimming                                                                                                      |\n| `env`                | `object`                  | `{}`                     | Environment variables to pass to the shell                                                                                                     |\n| `cwd`                | `string`                  | `undeinfed`              | The current working directory to execute the process within                                                                                    |\n| `uid`                | `number`                  | `undefined`              | The UID who owns the process                                                                                                                   |\n| `gid`                | `number`                  | `undefined`              | The GID who owns the process                                                                                                                   |\n| `alias`              | `object`                  | `{}`                     | Object list of command aliases                                                                                                                 |\n| `stdin`              | `stream.Readable`, `\"inherit\"`, `buffer` or `string` | `undefined`              | Either connect the stream to the proess STDIN or feed the given input into STDIN if its a string or buffer |\n\n\n**NOTES:**\n* Setting `log` or `log{Stdout,Stderr}` automatically implies the respective `logStdout` / `logStderr` function to be true\n* Setting `stdin=\"inherit\"` is the equivelent of setting `stdin=process.stdin` to connect the outer process STDIN pipe to the innner process\n\n\nexec.defaults\n-------------\nAn object containing the default options for `exec()` which can be globally changed.\n\n\nexec.split(cmd)\n---------------\nTake a command line and split it into a `child_process.spawn()` compatible array.\n\n\nexec.join(args)\n---------------\nTake a disected `child_process.spawn()` comaptible array and convert it into a single line, runnable shell command.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Fexec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmomsfriendlydevco%2Fexec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Fexec/lists"}