Looking for a solution in my ExpressJS setup with Pino logger. I am trying to create a class that can be initialized with a Pino logger.
Here is the code snippet:
import express, { NextFunction, Request, Response } from 'express';
import pino from 'pino-http';
const app = express();
const port = 8080;
app.use(pino());
app.use(async (req: Request, res: Response, next: NextFunction): Promise<void> => {
const logger: P.Logger = req.log;
const myClass = new MyClass(logger)
})
Encountering an issue as Typescript Compiler throws an error "Cannot find namespace P". It seems like req.log is categorized under
(property) IncomingMessage.log: P.Logger
. Any thoughts on what could be the problem here?
package.json
"dependencies": {
"express": "^4.17.1",
"express-async-handler": "^1.1.4",
"pino-http": "^5.8.0",
"rxjs": "^5.5.12",
"ws": "^3.3.3"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/jest": "^27.0.2",
"@types/node": "^16.10.2",
"@types/pino-http": "^5.8.0",
"@types/ws": "^8.2.0",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"eslint": "^7.32.0",
"jest": "^27.2.4",
"nodemon": "^2.0.13",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"tsc-watch": "^4.5.0",
"typescript": "^4.4.3"
}