{"library":"node-process","title":"Node Process","description":"node-process is a utility library for Node.js applications designed to simplify the management of sub-processes, enabling multi-threading and background task execution. Currently at version 1.0.1, its initial \"LIVE ready\" release suggests an active but relatively young project without a well-established release cadence yet. The library wraps Node.js's native `child_process.fork` functionality, abstracting away some complexities and offering a promise-based API for handling responses and errors. A key differentiator is its ability to manage both short-lived, single-response processes and \"sticky\" processes that remain open indefinitely until the main thread terminates, facilitating continuous background operations or long-running services. Communication between parent and child processes relies on `process.send`, with specific options for maintaining open connections in sticky processes. This simplifies common patterns for offloading CPU-intensive tasks or running concurrent operations without blocking the event loop, providing a more approachable alternative to direct `child_process` API usage.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-process"],"cli":null},"imports":["let node_process = require('node_process');","node_process.fork('path', args, keepOpen)","process.send(message, handle, options)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const node_process = require('node_process');\n\n// Example 1: One sub-process/thread that resolves once\nnode_process.fork('path_to_your_module.js', ['arg1', 'arg2'], true)\n.then((response) => {\n    // response is string|object sent from the module back to the main thread\n    // using process.send('string|object');\n    console.log('One-time process response:', response);\n})\n.catch((error) => {\n    console.error('One-time process error:', error);\n});\n\n// Example 2: A sticky process/thread that never ends until main thread is dead\n// The child module must call process.send(data, null, {keepOpen:true}); to remain open\nnode_process.fork('path_to_another_module.js', ['config_path'], false)\n.then((response) => {\n    // For sticky processes, this 'then' block is executed on *each* message from the child\n    // as long as the child sends with {keepOpen:true}\n    console.log('Sticky process message:', response);\n})\n.catch((error) => {\n    console.error('Sticky process error:', error);\n});\n\n/* Example content for 'path_to_your_module.js' or 'path_to_another_module.js':\n\nprocess.on('message', (message) => {\n    console.log('Child received:', message);\n    // Perform some task\n    const result = { status: 'done', data: 'Processed: ' + message[0] };\n    // For one-time process, process.send(result); is enough.\n    // For sticky, use: process.send(result, null, {keepOpen: true});\n    process.send(result, null, { keepOpen: true }); \n});\n*/","lang":"javascript","description":"Demonstrates how to fork both a single-execution sub-process and a 'sticky' long-running background process, including basic inter-process communication.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}