I have quite confusing issue in my plate, I have a server.js which is my first app entry point:
const test = require('./routers/test')
const express= require("express")
const pino = require('pino');
const expressPino = require('express-pino-logger');
const logger = pino({ level: process.env.LOG_LEVEL || 'info' });
const expressLogger = expressPino({ logger });
const app= express();
const port= process.env.port || 4000
app.use(expressLogger);
app.use(express.json());
app.use(test);
app.listen(port, ()=>{
logger.info(`Listening to port ${port}`);
});
As you see I have a logger(pino) and I use it and it works fine. Now I need to add a routes file to this entry point server file and the problem is exactly here. How can I pass down or use the logger I created in server.js in test.js route file(looking for best practices)?
const express = require('express');
const router = new express.Router();
router.get('test', (req, res)=>{
console.log("THIS CONSOLE.LOG NEEDS TO BE REPLACED WITH LOGGER.INFO");
res.send(udsData.getDummyUrlResponse())
});
module.exports = router