/knowledge-share-process-child-and-cluster

[KS][S] GuideSmiths Process Child + Cluster

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

[KS][S] GuideSmiths Process Child + Cluster

Este repo es parte de una formación interna en GuideSmiths

Bases teóricas

Standard Output

stdin vs stdout vs stderr

Contexto

I/O direction

Unix contexto

I/O Redirection

python3 exec/error.py > logs/stout_clean.log # Guardar solo el stdout
python3 exec/error.py >> logs/append.log  # Append del stdout
python3 exec/error.py &> logs/all.log # Guardar stdout y stderr
python3 exec/error.py 1> logs/stout.log # Guardar solo el stdout
python3 exec/error.py 2> logs/error.log # Guardar solo el stderr
python3 exec/error.py 1> logs/all_stout.log 2>&1 # Guardar el stdout (redirect de stderr)
python3 exec/error.py 2> logs/all_stderr.log 1>&2 # Guardar el error (redirect de stout)

Relación entre los procesos

Relación

Métodos esenciales

  • 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
  • child_process.execSync() una versión síncrona y bloqueante de child_process.exec() Doc
  • child_process.execFile() similar a child_process.exec(), excepto que genera el comando directamente sin generar primero un shell de forma predeterminada Doc
  • child_process.execFileSync() una versión síncrona y bloqueante de child_process.execFile() Doc
  • child_process.spawn() genera un shell y ejecuta un comando devolviendo un stream y que debemos gestionar por eventos Doc
  • child_process.spawnSync() una versión síncrona y bloqueante de child_process.spawn() Doc
  • child_process.fork() Es similar a child_process.spawn() solo que nos permite enviar mensajes al proceso hijo Doc

Contenidos

Process

Ejecutables

Child Process

Cluster

Recursos

Live Coding (T1C5) | Child processes con Nodejs y Firebase

Link a mi video de Youtube

Gestion de errores

Variables del Entorno

Librerías

  • dotenv Loads environment variables from .env for nodejs projects.
  • cross-env Set environment variables cross-platform.

Creando ejecutables

  • node-upstarter Easily create upstart services for your node apps
  • diable 😈 Daemonize the things out.
  • daemonize-process Daemonize the current Node.js process
  • daemonix A utility for creating daemons out of NodeJS applications.

Child Process

Librerías

Cluster

Librerias