Closed shaunstone0 closed 3 years ago
I have a code that uses a winstonIntance, however I get the error:
transports or a winstonInstance are required by express-winston middleware\nError:
my Express Application:
const express = require('express'); const bodyParser = require('body-parser'); const expressWinston = require('express-winston'); const router = require('./routes/createRouter.js')(); module.exports = ({ database, logger }) => express() .use( expressWinston.logger({ winstonInstance: logger, msg: '{{res.statusCode}} {{req.method}} {{req.url}} {{res.responseTime}}ms', meta: false, }) ) .use(bodyParser.urlencoded({ extended: true })) .use(bodyParser.json()) .use((req, res, next) => { req.base = `${req.protocol}://${req.get('host')}`; req.logger = logger; req.db = database; console.log(logger); return next(); }) .use(express.static('./public')) .use('/api', router) .use((error, req, res, next) => { logger.error(error, error); res.status(error.status || 500).json({ error }); });
my logger.js
const logger = (module.exports = require('winston')); logger.add( new logger.transports.File({ filename: 'debugFile.log', level: 'debug', handleExceptions: true, humanReadableUnhandledException: true, exitOnError: true, json: false, maxsize: 104857600, maxFiles: 5, }) ); logger.add( new logger.transports.Console({ level: 'error', handleExceptions: true, humanReadableUnhandledException: true, exitOnError: true, }) );
I have researched, and I think it may be a problem with Winston- however, it could be a problem I created also.
my package.json:
"dependencies": { "bcrypt": "^5.0.0", "body-parser": "^1.19.0", "cookie-parser": "^1.4.5", "dotenv": "^8.2.0", "express": "^4.17.1", "express-winston": "^4.0.5", "glob": "^7.1.6", "mongoose": "^5.10.2", "winston": "^3.3.3" } }
I have a code that uses a winstonIntance, however I get the error:
transports or a winstonInstance are required by express-winston middleware\nError:
my Express Application:
my logger.js
I have researched, and I think it may be a problem with Winston- however, it could be a problem I created also.
my package.json: