{"_id":"spork","_rev":"10-473427e7350836d8fd273dfec4dc12a0","name":"spork","description":"Stress-free node child process spawning and management","dist-tags":{"latest":"0.3.2"},"versions":{"0.0.0":{"author":{"name":"Dominic Tarr"},"name":"spork","description":"spawn a child process and setup rpc to it with one easy utensil.","version":"0.0.0","repository":{"url":""},"main":"spork.js","scripts":{"test":"meta-test test/*.js"},"engines":{"node":"*"},"dependencies":{},"devDependencies":{},"_id":"spork@0.0.0","_engineSupported":true,"_npmVersion":"1.0.6","_nodeVersion":"v0.4.7","_defaultsLoaded":true,"dist":{"shasum":"6000a230cb401167817989eb8e09301aa731f7ec","tarball":"https://registry.npmjs.org/spork/-/spork-0.0.0.tgz","integrity":"sha512-apMy4GS0LiE/EjR4XyZ6nJ8sZusz3FH/3MdTA7H4ZHZZNLZKaPefXmvcQu0VTwB83l+8RN8+5q7C8PZc4ckxLg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCA3njgMzbRSAd+DjfLLhYWw4IpnWoXsODGP0O3zFR9VgIgINX6/VJCMkqWjs3IDStfLMlSOBhSFs6YM/DtTo2P1fE="}]}},"0.3.0":{"name":"spork","version":"0.3.0","description":"Stress-free node child process spawning and management","keywords":["spork","node","child","process","spawn","fork","cli"],"homepage":"https://github.com/justinhelmer/spork","bugs":{"url":"https://github.com/justinhelmer/spork/issues","email":"jhelmer25@gmail.com"},"license":"MIT","author":{"name":"Justin Helmer jhelmer25@gmail.com"},"main":"./index.js","repository":{"type":"git","url":"git+https://github.com/justinhelmer/spork.git"},"dependencies":{"chalk":"^1.1.1","forever-monitor":"^1.7.0","lodash":"^4.1.0","node-clean-exit":"^0.2.1","pluralize":"^1.2.1"},"devDendencies":{"jscs":"^2.9.0","jshint":"^2.9.1"},"engines":{"node":">=0.12"},"gitHead":"a608afcfc8a50ccf4ab1435c4c716aa46bf06835","_id":"spork@0.3.0","scripts":{},"_shasum":"ee5d3b2819833bd6370f87f0c8439b8b46fc56e5","_from":".","_npmVersion":"3.5.3","_nodeVersion":"0.12.9","_npmUser":{"name":"justinhelmer","email":"jhelmer25@gmail.com"},"dist":{"shasum":"ee5d3b2819833bd6370f87f0c8439b8b46fc56e5","tarball":"https://registry.npmjs.org/spork/-/spork-0.3.0.tgz","integrity":"sha512-LXf4u5Z3CIFgsRQAanKbO3XEKMymSTofcsUCodo1A2gjIfL9hqM0hBulBd4gwI6fXLuJDCEOu71d1H2iHSYkdg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD6P+Yes52DcY/rEkPLUV/DbPcIzqFWlisxOxsNXdC1kAIgBPI1fL+PS07FhxZKypHRbTn5mWBlsu/cYEEqqFj8pvk="}]},"maintainers":[{"name":"dominictarr","email":"dominic.tarr@gmail.com"},{"name":"justinhelmer","email":"jhelmer25@gmail.com"}],"_npmOperationalInternal":{"host":"packages-6-west.internal.npmjs.com","tmp":"tmp/spork-0.3.0.tgz_1454381814990_0.4488026842009276"}},"0.3.1":{"name":"spork","version":"0.3.1","description":"Stress-free node child process spawning and management","keywords":["spork","node","child","process","spawn","fork","cli"],"homepage":"https://github.com/justinhelmer/spork","bugs":{"url":"https://github.com/justinhelmer/spork/issues","email":"jhelmer25@gmail.com"},"license":"MIT","author":{"name":"Justin Helmer jhelmer25@gmail.com"},"main":"./index.js","repository":{"type":"git","url":"git+https://github.com/justinhelmer/spork.git"},"dependencies":{"chalk":"^1.1.1","forever-monitor":"^1.7.0","lodash":"^4.1.0","node-clean-exit":"^0.2.1","pluralize":"^1.2.1"},"devDendencies":{"jscs":"^2.9.0","jshint":"^2.9.1"},"engines":{"node":">=0.12"},"gitHead":"f1835f9b5de49109f8b8006d02643de25e8b0a4b","_id":"spork@0.3.1","scripts":{},"_shasum":"d61a12edaf4046561087e3122e67db7d8fe31b32","_from":".","_npmVersion":"3.5.3","_nodeVersion":"0.12.9","_npmUser":{"name":"justinhelmer","email":"jhelmer25@gmail.com"},"dist":{"shasum":"d61a12edaf4046561087e3122e67db7d8fe31b32","tarball":"https://registry.npmjs.org/spork/-/spork-0.3.1.tgz","integrity":"sha512-2EpXfzw/H6dJV8icIdnS+I40C3hylUxpCKMa/JprGUPrzRdy8DGZ7ehhg+t5Aum7KUnNH93i3CsVZJ2ErT4OjA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGjuIFmjmukMghZKrcVVDWVh2dvbCS4j0SQVnacCBizUAiEA4uoheeB68/3CawznViR78Xl0Vo+7AiPeQzGB13KS7t8="}]},"maintainers":[{"name":"justinhelmer","email":"jhelmer25@gmail.com"}],"_npmOperationalInternal":{"host":"packages-9-west.internal.npmjs.com","tmp":"tmp/spork-0.3.1.tgz_1454441802081_0.9261581576429307"}},"0.3.2":{"name":"spork","version":"0.3.2","description":"Stress-free node child process spawning and management","keywords":["spork","node","child","process","spawn","fork","cli"],"homepage":"https://github.com/justinhelmer/spork","bugs":{"url":"https://github.com/justinhelmer/spork/issues","email":"jhelmer25@gmail.com"},"license":"MIT","author":{"name":"Justin Helmer jhelmer25@gmail.com"},"main":"./index.js","repository":{"type":"git","url":"git+https://github.com/justinhelmer/spork.git"},"dependencies":{"chalk":"^1.1.1","forever-monitor":"^1.7.0","lodash":"^4.1.0","node-clean-exit":"^0.2.1","pluralize":"^1.2.1"},"devDendencies":{"jscs":"^2.9.0","jshint":"^2.9.1"},"engines":{"node":">=0.12"},"gitHead":"f02993b330bbb2de110626a8f32e755dea7cbbf1","_id":"spork@0.3.2","scripts":{},"_shasum":"f43cef542221e59023034e3cd217f7bd93237b97","_from":".","_npmVersion":"3.5.3","_nodeVersion":"0.12.9","_npmUser":{"name":"justinhelmer","email":"jhelmer25@gmail.com"},"dist":{"shasum":"f43cef542221e59023034e3cd217f7bd93237b97","tarball":"https://registry.npmjs.org/spork/-/spork-0.3.2.tgz","integrity":"sha512-H0Y3h8r7lK9xP6uHxpI9uFSz5rlgmf6sZUbhqNaRLmU16gV1/qzX/2kzTlxxnqjGZzj/WCnB3IgLSjAOc8mYSg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDJlYsDROdKNjVD0nw8qshdG4O0VlaunL3K/hZt9RZG8wIhAKRHeS+Q15h3l0pfs8S5Oc6BVs1gRktBXNBE8nRdWQCg"}]},"maintainers":[{"name":"justinhelmer","email":"jhelmer25@gmail.com"}],"_npmOperationalInternal":{"host":"packages-6-west.internal.npmjs.com","tmp":"tmp/spork-0.3.2.tgz_1455424467477_0.5439095394685864"}}},"maintainers":[{"name":"justinhelmer","email":"jhelmer25@gmail.com"}],"time":{"modified":"2022-06-26T23:02:32.978Z","created":"2011-05-22T08:40:54.823Z","0.0.0":"2011-05-22T08:40:56.577Z","0.3.0":"2016-02-02T02:56:55.664Z","0.3.1":"2016-02-02T19:36:42.733Z","0.3.2":"2016-02-14T04:34:29.334Z"},"author":{"name":"Justin Helmer jhelmer25@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/justinhelmer/spork.git"},"readme":"# spork\nStress-free node child process spawning and management. A small wrapper around [forever-monitor](https://github.com/foreverjs/forever-monitor)\nwith a simple interface.\n\n[![npm package](https://badge.fury.io/js/spork.svg)](https://www.npmjs.com/package/spork)\n[![node version](https://img.shields.io/node/v/spork.svg?style=flat)](http://nodejs.org/download/)\n[![dependency status](https://david-dm.org/justinhelmer/spork.svg)](https://github.com/justinhelmer/spork)\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/justinhelmer/spork/issues)\n\nNot everything has a `node` adapter. Often times, there is a need to spawn a child process to run another script (maybe even fork another `node` process).\n\nForking and managing [child processes](https://nodejs.org/api/child_process.html) in `node` can prove challenging. If something fails in the pipe, you can be\nleft over with `phantom processes` running in the background. Over time, these can accumulate and result in strange issues such as blocked ports,\nmisbehaving debug tools, \"random\" exits, etc. Even a number of popular `node` modules, `grunt` plugins, etc. fail to exit cleanly. \n\nAdditionally, the [child_process.spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) interface is\nnot very desirable. It was written for flexibility, but the majority of the time it is used the same way. Managing all of this correctly across multiple\nprocesses and multiple scripts can be cumbersome and error-prone.\n\nTo defer this redudancy and avoid the risk, `spork` was created to try to make spawning and forking smoother -- hence the name.\n\n## Overview\n\n`Spork` follows a very similar syntax to `node` core's [child_process.spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)\nto keep the interface simple. It also takes advantage of the power of [forever-monitor](https://github.com/foreverjs/forever-monitor) to add some much-needed\nrobustness to the interface. The syntax should be straight-forward and familiar:\n\n```js\nconst spork = require('spork');\nspork(command, args, options);\n```\n\nBesides spawning child processes, `spork` can do a few other things:\n\n - manage and kill processes that fail - clean exits using [node-clean-exit](https://github.com/justinhelmer/node-clean-exit)\n - capture and/or act on `stdio` events\n - exit automatically on `failure` and/or `success` (configurable)\n - inherit parent stdio automatically, or suppress entirely\n - retain `ANSI` color character sequences through the pipe\n \n## Installation\n\n```bash\n$ npm install --save spork\n```\n \n## The interface\n\n[Take me straight to the API](#spawncommand-argsoptions-options)\n\nIn its simplest form:\n\n```js\nspork('command', {exit: true}); // process will automatically exit when the command fails or succeeds\n```\n\nNormally, _all_ of this is required for just **one** process, in order to spawn it, act on data events, and exit cleanly:\n\n```js\nconst done = async();\n\nlet child = spawn('command', ['--arg1', '--arg2'], {\n  env: _.extend(process.env, {\n    WHATEVER: 'isNeeded'\n  }),\n\n  stdio: [process.stdin, 'pipe', 'pipe']\n});\n\nchild.stdout.setEncoding('utf8');\nchild.stderr.setEncoding('utf8');\n\nchild.stdout.on('data', function(data) {\n  // .. do something\n  \n  process.stdout.write(data);\n});\n\nlet errorBuffer = '';\nchild.stderr.on('data', function(data) {\n  errorBuffer += data;\n});\n\nchild.on('close', function(code) {\n  if (code) {\n    customErrorHandler(errorBuffer, code);\n  } else {\n    done();\n  }\n});\n\nchild.on('error', function(err) {\n  console.error(err);\n  process.exit(99);\n});\n\nprocess.stdin.resume();\n\nprocess.on('exit', exitHandler);\nprocess.on('SIGINT', _.partial(exitHandler, {exitCode: 2}));\nprocess.on('uncaughtException', _.partial(exitHandler, {exitCode: 99}));\n\nfunction exitHandler(exitData, err) {\n  if (err && err.stack) {\n    console.error(err);\n    process.exit(1);\n  }\n  \n  child.kill();\n\n  if (exitData && exitData.exit) {\n    process.exit(exitData.exit);\n  }\n}\n```\n\nInstead, just do this, to produce the same result:\n\n```js\nspork('command', ['--arg1', '--arg2'], {env: {WHATEVER: 'isNeeded'}})\n    .on('stdout', function(data) {\n      // .. do something\n    })\n    .on('exit:code', function(code) {\n      // .. do something\n      process.exit(code);\n    });\n```\n\nOr, let `spork` handle everything:\n\n```js\nspork('command', ['--arg1', '--arg2'], {exit: true});\n```\n\n## spawn(command, [args|options], [options])\n\n- @param **command** _{string}_ - The command to run.\n- @param **[args]** _{mixed}_ - The arguments to pass to the command, as an _{array}_. Also can pass _{object}_ **[options]**\n                                in this position and ignore **[args]**.\n- @param **[options]** _{object}_ - Additional options to be passed to\n                                    [forever-monitor](https://github.com/foreverjs/forever-monitor#options-available-when-using-forever-in-nodejs),\n                                    plus custom options [below](#options).\n- @returns _{[forever.monitor](https://github.com/foreverjs/forever-monitor)}_\n- @see [child_process.spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)\n- @see [forever-monitor](https://github.com/foreverjs/forever-monitor)\n\n## Options\n\nAll options [here](https://github.com/foreverjs/forever-monitor#options-available-when-using-forever-in-nodejs), plus:\n- **exit** _{mixed}_ - Close the child process on exit. Can be `success`, `failure`, `always`, `true` (alias for `always`), or `false`. Defaults to `failure`.\n- **quiet** _{boolean}_ - Output nothing (suppress `STDOUT` and `STDERR`. Defaults to `false`.\n- **stdio** _{array}_ - Identify whether or not to pipe `STDIN`, `STDOUT`, `STDERR` to the parent process. Defaults to `['inherit', 'inherit', 'inherit']`.\n- **verbose** _{mixed}_ - Output more. Can be a boolean or a number. The higher the number, the higher the verbosity. Defaults to `false`.\n    \n> You can completely nix the built-in `stdio` inheritence using `stdio: [null, null, null]` and manage it all yourself.\n\n## Events\n\n[Here](https://github.com/foreverjs/forever-monitor#events-available-when-using-an-instance-of-forever-in-nodejs)\n\n## Contributing\n\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/justinhelmer/spork/issues)\n\n## Licence\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Justin Helmer\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","readmeFilename":"README.md","homepage":"https://github.com/justinhelmer/spork","keywords":["spork","node","child","process","spawn","fork","cli"],"bugs":{"url":"https://github.com/justinhelmer/spork/issues","email":"jhelmer25@gmail.com"},"license":"MIT"}