Integrate Winston into node application

88 Views Asked by At

I have my node application architecture like this-

app.js

import express from 'express';
var app = express();
app.use('/route', Router);

Router.js

import express from 'express';
var router = express.Router();
router.get('/route', Router.routerController);

controller.js

exports.routerController = async function (req, res) {
  const { id } = req.params;
  try {
    // Actual API call
  } catch (error) {

  }
};

What will be the best way to integrate Winston for logging into such architecture. Is there a way in which I can integrate Winston in the entire application without placing log calls in every controller?

1

There are 1 best solutions below

1
On

You can use middleware for that. see sth like this https://www.npmjs.com/package/express-winston