{"id":15780250,"url":"https://github.com/ulisesgascon/knowledge-share-process-child-and-cluster","last_synced_at":"2025-03-31T16:34:45.539Z","repository":{"id":72138348,"uuid":"203942673","full_name":"UlisesGascon/knowledge-share-process-child-and-cluster","owner":"UlisesGascon","description":"[KS][S] GuideSmiths Process Child + Cluster","archived":false,"fork":false,"pushed_at":"2019-08-23T13:48:14.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T20:02:26.476Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UlisesGascon.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}},"created_at":"2019-08-23T07:00:29.000Z","updated_at":"2019-08-24T07:25:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"f0a8c80f-36e3-403c-95ef-0e69dc01283f","html_url":"https://github.com/UlisesGascon/knowledge-share-process-child-and-cluster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Fknowledge-share-process-child-and-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Fknowledge-share-process-child-and-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Fknowledge-share-process-child-and-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Fknowledge-share-process-child-and-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UlisesGascon","download_url":"https://codeload.github.com/UlisesGascon/knowledge-share-process-child-and-cluster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246498429,"owners_count":20787313,"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","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-10-04T18:41:00.370Z","updated_at":"2025-03-31T16:34:45.510Z","avatar_url":"https://github.com/UlisesGascon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [KS][S] [GuideSmiths](https://guidesmiths.com/) Process Child + Cluster\n\nEste repo es parte de una formación interna en [GuideSmiths](https://guidesmiths.com/)\n\n## Bases teóricas\n\n### Standard Output\n\n#### stdin vs stdout vs stderr\n\n![Contexto](http://img.c4learn.com/2010/01/Stdstreams-notitle.svg_.png)\n\n#### I/O direction\n\n![Unix contexto](https://bash.cyberciti.biz/uploads/bashwiki/9/9b/Output-redirect_filename.png)\n\n#### I/O Redirection\n\n```bash\npython3 exec/error.py \u003e logs/stout_clean.log # Guardar solo el stdout\npython3 exec/error.py \u003e\u003e logs/append.log  # Append del stdout\npython3 exec/error.py \u0026\u003e logs/all.log # Guardar stdout y stderr\npython3 exec/error.py 1\u003e logs/stout.log # Guardar solo el stdout\npython3 exec/error.py 2\u003e logs/error.log # Guardar solo el stderr\npython3 exec/error.py 1\u003e logs/all_stout.log 2\u003e\u00261 # Guardar el stdout (redirect de stderr)\npython3 exec/error.py 2\u003e logs/all_stderr.log 1\u003e\u00262 # Guardar el error (redirect de stout)\n```\n\n### Relación entre los procesos\n\n![Relación](https://raw.githubusercontent.com/Fictizia/Master-en-Programacion-FullStack-con-JavaScript-y-Node.js_ed3/master/assets/clase74/d4172e11-a496-4696-993e-6f818f1e891f.png)\n\n### Métodos esenciales\n\n- `child_process.exec()` genera un shell y ejecuta un comando dentro de ese shell, pasando el `stdout` y el `stderr` al callback cuando se completa. Internamente utiliza `buffer` [Doc](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)\n- `child_process.execSync()` una versión síncrona y bloqueante de `child_process.exec()` [Doc](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options)\n- `child_process.execFile()` similar a `child_process.exec()`, excepto que genera el comando directamente sin generar primero un shell de forma predeterminada [Doc](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback)\n- `child_process.execFileSync()` una versión síncrona y bloqueante de `child_process.execFile()` [Doc](https://nodejs.org/api/child_process.html#child_process_child_process_execfilesync_file_args_options)\n- `child_process.spawn()` genera un shell y ejecuta un comando devolviendo un `stream` y que debemos gestionar por eventos [Doc](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)\n- `child_process.spawnSync()` una versión síncrona y bloqueante de `child_process.spawn()` [Doc](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options)\n- `child_process.fork()` Es similar a `child_process.spawn()` solo que nos permite enviar mensajes al proceso hijo [Doc](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)\n\n## Contenidos\n\n**[Process](https://github.com/Fictizia/Master-en-Programacion-FullStack-con-JavaScript-y-Node.js_ed3/blob/master/teoria/clase74.md#process)**\n\n- [Información del proceso](process/basic.js)\n- [Variables de Entorno](process/env.js)\n- [Gestión de errores/salidas](process/exit.js)\n\n**[Ejecutables](https://github.com/Fictizia/Master-en-Programacion-FullStack-con-JavaScript-y-Node.js_ed3/blob/master/teoria/clase74.md#creando-ejecutables)**\n\n- [Crear un ejecutable](executables/basic.js)\n\n**[Child Process](https://github.com/Fictizia/Master-en-Programacion-FullStack-con-JavaScript-y-Node.js_ed3/blob/master/teoria/clase74.md#child-process)**\n\n- exec\n  - [Ejemplo simple](exec/basic.js)\n  - [Ejemplo completo](exec/error.js)\n  - [Encapsular la librería `youtube-dl`](exec/youtube_downloader.js)\n  - [Procesos hijo en paralelo con `youtube-dl`](exec/youtube_bulk.js)\n- spawn\n  - [Ping infinito a un servidor](spawn/basic.js)\n  - [Ping y append juntos](spawn/ping_log.js)\n\n**[Cluster](https://github.com/Fictizia/Master-en-Programacion-FullStack-con-JavaScript-y-Node.js_ed3/blob/master/teoria/clase74.md#cluster)**\n\n- [Servidor Normal](cluster/server.js)\n- [Servidor Clusterizado](cluster/cluster-server.js)\n\n## Recursos\n\n### Live Coding (T1C5) | Child processes con Nodejs y Firebase\n\n[![Link a mi video de Youtube](https://i.ytimg.com/vi/2n5_zYdVypc/maxresdefault.jpg)](https://www.youtube.com/watch?v=2n5_zYdVypc\u0026feature=youtu.be)\n\n### Gestion de errores\n\n- [The Node.js Way - Understanding Error-First Callbacks](http://fredkschott.com/post/2014/03/understanding-error-first-callbacks-in-node-js/)\n- [Node.js Best Practices | Error Handling Practices](https://github.com/i0natan/nodebestpractices#2-error-handling-practices)\n- [Building Robust Node Applications: Error Handling](https://strongloop.com/strongblog/robust-node-applications-error-handling/)\n- [Joyent | Production Practices](https://www.joyent.com/node-js/production/design/errors)\n- [How to prevent your Node.js process from crashing](https://medium.com/dailyjs/how-to-prevent-your-node-js-process-from-crashing-5d40247b8ab2)\n\n### Variables del Entorno\n\n- [Working with Environment Variables in Node.js](https://www.twilio.com/blog/2017/08/working-with-environment-variables-in-node-js.html)\n- [process.env: What it is and why/when/how to use it effectively](https://codeburst.io/process-env-what-it-is-and-why-when-how-to-use-it-effectively-505d0b2831e7)\n- [Environment Variables in Node.js](https://medium.com/@maxbeatty/environment-variables-in-node-js-28e951631801)\n- [Here’s how you can actually use Node environment variables](https://medium.freecodecamp.org/heres-how-you-can-actually-use-node-environment-variables-8fdf98f53a0a)\n- [Using dotenv package to create environment variables](https://medium.com/@thejasonfile/using-dotenv-package-to-create-environment-variables-33da4ac4ea8f)\n- [Configuration settings in Node with dotenv](https://medium.com/@jonjam/configuration)\n- [Managing Configurations in Node.JS apps with dotenv and convict](https://medium.com/@sherryhsu/managing-configurations-in-node-js-apps-with-dotenv-and-convict-d74070d37373)\n\n#### Librerías\n\n- [dotenv](https://github.com/motdotla/dotenv) *Loads environment variables from .env for nodejs projects.*\n- [cross-env](https://github.com/kentcdodds/cross-env) *Set environment variables cross-platform.*\n\n\n### Creando ejecutables\n\n- [node-upstarter](https://github.com/carlos8f/node-upstarter) *Easily create upstart services for your node apps*\n- [diable](https://github.com/IonicaBizau/diable) 😈 *Daemonize the things out.*\n- [daemonize-process](https://github.com/silverwind/daemonize-process#readme) *Daemonize the current Node.js process*\n- [daemonix](https://github.com/BlueRival/daemonix) *A utility for creating daemons out of NodeJS applications.*\n\n### Child Process\n\n- [Node.js Child Processes: Everything you need to know](https://medium.freecodecamp.org/node-js-child-processes-everything-you-need-to-know-e69498fe970a)\n- [Understanding execFile, spawn, exec, and fork in Node.js](https://dzone.com/articles/understanding-execfile-spawn-exec-and-fork-in-node)\n- [Node.js: managing child processes](http://krasimirtsonev.com/blog/article/Nodejs-managing-child-processes-starting-stopping-exec-spawn)\n- [Getting to know Node’s child_process module](https://medium.com/the-guild/getting-to-know-nodes-child-process-module-8ed63038f3fa)\n- [Nodejs Doc | exec](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)\n- [Nodejs Doc | execFile](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback)\n- [Nodejs Doc | fork](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)\n- [Nodejs Doc | execSync](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options)\n- [Nodejs Doc | execFileSync](https://nodejs.org/api/child_process.html#child_process_child_process_execfilesync_file_args_options)\n- [Nodejs Doc | spawnSync](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options)\n- [Nodejs Doc | spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)\n\n#### Librerías\n\n- [execa](https://github.com/sindresorhus/execa#readme)\n- [opn](https://github.com/sindresorhus/opn#readme)\n- [node-worker-farm](https://github.com/rvagg/node-worker-farm)\n- [spawnd](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/spawnd)\n\n### Cluster\n\n- [Scaling Node.js Applications](https://medium.freecodecamp.org/scaling-node-js-applications-8492bd8afadc)\n- [Taking Advantage of Multi-Processor Environments in Node.js](http://blog.carbonfive.com/2014/02/28/taking-advantage-of-multi-processor-environments-in-node-js/#tldr)\n- [Modo cluster para node.js](http://pinchito.es/2013/modo-cluster.html)\n- [How to Create a Node.js Cluster for Speeding Up Your Apps](https://www.sitepoint.com/how-to-create-a-node-js-cluster-for-speeding-up-your-apps/)\n- [How to scale your Node.js server using clustering](https://medium.freecodecamp.org/how-to-scale-your-node-js-server-using-clustering-c8d43c656e8f)\n- [Clustering in NodeJs — Performance Optimization](https://medium.com/tech-tajawal/clustering-in-nodejs-utilizing-multiple-processor-cores-75d78aeb0f4f)\n- [Understanding the NodeJS cluster module](http://www.acuriousanimal.com/2017/08/12/understanding-the-nodejs-cluster-module.html)\n\n#### Librerias\n\n- [luster](https://github.com/nodules/luster)\n- [cluster-map](https://www.npmjs.com/package/cluster-map)\n- [PM2](https://www.npmjs.com/package/pm2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulisesgascon%2Fknowledge-share-process-child-and-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fulisesgascon%2Fknowledge-share-process-child-and-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulisesgascon%2Fknowledge-share-process-child-and-cluster/lists"}