↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Node.js Best Practices — Error Handling and Logging

The article groups several practices for keeping a Node.js app maintainable when things fail. It points to GraphQL for documenting API errors, suggests stopping the process when an unknown error occurs, and recommends using a mature logger and monitoring tool to make failures easier to see.

Reading notes
#

  • GraphQL can document API errors through schema and comments, while also giving strong typing and autocomplete for queries.
  • When an unknown error occurs, the process should exit and be restarted with a tool such as Forever or PM2.
  • A logger such as Winston, Bunyan, Log4js, or Pino helps surface activity and errors; the example uses express-winston with Express.
  • Automated tests are preferred over manual testing because they can cover both success and error cases quickly.
  • APM or status monitoring tools can track CPU, memory usage, response time, requests per second, and other health metrics.
  • Unhandled promise rejections and error events should be caught with catch handlers or process.on(‘unhandledRejection’).