winston logger | Log into MongoDB | File | Console | nodejs tutorial

Опубликовано: 11 Март 2026
на канале: Technical Babaji (Tarique Akhtar)
43,825
543

github link : https://github.com/Tariqu/winston_log...
```
const {

createLogger,
format,
transports
} = require("winston");
require('winston-mongodb').MongoDB;
const logger = createLogger({
transports: [
new transports.MongoDB({
db: process.env.MONGODB_URI,
level: 'silly',
options: {
useUnifiedTopology: true
}
}),
new transports.File({
filename: "error.log",
level: "error",
format: format.combine(format.timestamp(), format.json())
}),
new transports.File({
filename: "info.log",
level: "info",
format: format.combine(format.timestamp(), format.json())
}),
]
});
module.exports = logger;
```

Hello friends its me tarique akhtar ansari in this video I am going to show you how to log properly into console,
into file and into the database using winston don't worry guyyz I have given github link in the discription,

you can checkout and get get the source code of this video.



let me tell you the to most importent reason of doing log



1. first thing as a developer point of view

-------------------------------------------

when we work on development we normally use console to see application log

but once your application moved into the production server and users are started using your application

then if somthing went wrong like application crashed or giving wrong output then you can't check into the console

but if you have log into file or into the database then you can check and identify the mistakes ok



2. sencond thing

----------------

if you have log of every activity happening in your application then you can process that log and generate some useful information

Just take an example of facebook. Facebook has billions of users and they have log of every activity of the users



1. just imagine how many different types of information can generate from that log

even we can't imagine how much information we can generate from log



ok so lets jump into the coding



install

--------

1. npm install winston

2. npm install winston-mongodb



then create winston logger object inside that object define transports then use that object to log into console | file | mongodb