Skip to content

a boilerplate to build REST API's with Express, Prisma and Docker following best node.js practices.

Notifications You must be signed in to change notification settings

raulingg/nodejs-api-boilerplate

Repository files navigation

Products JSON API

Good Practices

This repo somewhat follows the best practices from nodebestpractices repo in Github.

Logging

Levels

  • Fatalfatal: Used for reporting about errors that are forcing shutdown of the application.
  • Errorerror: Used for logging serious problems occurred during execution of the program.
  • Warningwarn: Used for reporting non-critical unusual behavior.
  • Infoinfo: Used for informative messages highlighting the progress of the application for sysadmins and end users.
  • Debugdebug: Used for debugging messages with extended information about application processing.
  • HTTPhttp: Used for logging HTTP requests.

Logging response time

The current logger (Pino) logs by default the response time of every request with the key responseTime.

Note The responseTime value will be in milliseconds (ms).

Why don't store the response time in a file?

Log destinations should not be hard-coded by developers within the application code, but instead should be defined by the execution environment the application runs in. Developers should write logs to stdout using a logger utility and then let the execution environment (container, server, etc.) pipe the stdout stream to the appropriate destination (i.e. Splunk, Graylog, ElasticSearch, etc.).

🔗 Read More: Log Routing

CORS configuration

CORS will be available when NODE_ENV envar is set to production. To specify which origins will be allowed to make requests, set the CORS_ORIGINS envar, otherwise no origin will be allowed.

  • To allow any origin CORS_ORIGINS=*
  • To allow specific origins CORS_ORIGINS=mydomain.com,other-domain.com

About

a boilerplate to build REST API's with Express, Prisma and Docker following best node.js practices.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •