Wonder how to remove console.logs in you nodeJS code. Well use a logger. The bunyan logger can simply logs messages to different streams in JSON format.
npm install bunyan
Create the logger file
After installing bunyan create a file. In my case I create a file called logger.js. First include the bunyan library.
You can specify the log level according to you need.
There’s a cool feature as Streams in bunyan which allows us to use different streams to log our output. Let’s say that I want to log all the errors to a external log file and the info level logs (details of operations to standard output) then we can use streams as follows.