Patrones de dise帽o en Node.js

1

Qu茅 es Node.js y c贸mo impulsa tu negocio

2

Patrones de dise帽o esenciales en Node.js

3

Patr贸n Singleton y Factory en JavaScript

4

Implementaci贸n pr谩ctica de Singleton y Factory en JavaScript

5

Implementaci贸n del patr贸n Observer con EventEmitter en Node.js

6

Implementaci贸n de Middlewares en Node.js sin Express

7

Decorators e inyecci贸n de dependencias en JavaScript

Flujo de Datos con Node.js

8

Aprende qu茅 son Buffer y Streams en Node.js

9

C贸mo utilizar streams y pipelines en Node.js

10

C贸mo funciona el Event Loop en Node.js

11

Qu茅 es Libuv y c贸mo maneja la asincron铆a en Node.js

12

Estrategias para ejecutar c贸digo as铆ncrono en Node.js

Debugging y Diagn贸stico en Node.js

13

C贸mo utilizar el Debugger en Node.js para solucionar problemas

14

Uso de Diagnostic Channels en Node.js para observabilidad y diagn贸stico

15

Instrumentaci贸n y m茅tricas clave en performance para aplicaciones Node.js

16

Control de errores globales y manejo de se帽ales en Node.js

17

Implementaci贸n Eficiente de Logs con Pino en Node.js

Performance en Node.js

18

An谩lisis del event loop en aplicaciones Node.js usando Nsolid

19

C贸mo Diagnosticar y Solucionar Memory Leaks en Aplicaciones Node.js

20

Optimizar rendimiento en Node.js con Worker Threads y Child Processes

21

Optimiza y Escala Aplicaciones Node.js con T茅cnicas de Caching

Creando CLIs con Node.js

22

C贸mo crear aplicaciones CLI con Node.js

23

C贸mo Crear un CLI con Minimist y Manejar Argumentos en Node.js

24

Creaci贸n de un CLI con Node.js y Google Generative AI

25

Creaci贸n de Chat con IA usando CLI en Node

26

C贸mo Crear e Instalar tu Propio CLI de Node con npm

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
14 Hrs
51 Min
4 Seg

Control de errores globales y manejo de se帽ales en Node.js

16/26
Resources

Creating robust applications in Node.js involves properly handling global errors and system signals. Many developers overlook global events that allow to control unexpected situations, so it is important to integrate and understand them in order to maintain the stability of the application.

Why use global events such as uncaughtException?

The event called uncaughtException allows to capture errors that are not explicitly controlled within the code. When an unexpected error is generated and it is not inside a block that can handle it, this event is fired automatically informing about the error and avoiding the uncontrolled crash of the application.

To implement it, it is only necessary to add it to the process module as follows:

process.on('uncaughtException', (error)  =>  {    console.error('An uncontrolled error was caught:', error);});

This makes it easy to identify exactly where the problem occurred and correct it quickly.

What is the benefit of using unhandledRejection?

The unhandledRejection event detects and controls rejections of promises that do not have catch events defined. This type of rejections are frequent in applications that use promises and can cause unexpected failures.

Adding this event is simple:

process.on('unhandledRejection', (reason, promise)  =>  {    console.error('Promise rejected and not handled:', reason);});

By having this control, it is possible to clearly diagnose rejections without explicit handling and maintain continuous operation of the server.

How to handle system signals for controlled shutdowns?

System signals tell the application to perform a controlled exit, an orderly shutdown that maintains the integrity of active processes. Some common signals are:

  • SIGINT: Issued when control C is pressed.
  • SIGTERM: Signal to terminate programs sent by external sources.

Implementing them is possible by listening to each signal and managing the shutdown:

['SIGINT', 'SIGTERM', 'SIGUSR1', 'SIGUSR2'].forEach((signal)  =>  {    process.on(signal,  ()  =>  {        console.log(`Received signal ${signal}`);        process.exit(1); // Controlled exit indicating error.     });});

This approach allows the application to terminate its processes cleanly and in a safe state when it detects shutdowns from the operating system.

I invite you to share your experience controlling global events and signals in your Node.js projects; tell me how you have solved unexpected errors or abrupt exits so far.

Contributions 0

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?