Backend debugging and logging
Two things are very important for debugging. The first is that we need to implement logging for our backend in case we receive errors from our users, while the second is that we need to look into Postman to debug our GraphQL API efficiently.
So, let's get started with logging.
Logging in Node.js
The most popular logging package for Node.js is called winston
. Install and configure winston
by following these steps:
- Install
winston
withnpm
:npm install --save winston
- Next, create a new folder for all of the helper functions from the backend:
mkdir src/server/helpers
- Then, insert a
logger.js
file into the new folder with the following content:import winston from 'winston'; let transports = [ new winston.transports.File({ filename: 'error.log', level: 'error', }), new winston.transports.File({ ...