mongoose-morgan without GET request logging

171 views Asked by At

Hey In my project I'm using mongoose-morgan.It is logging all the GET,POST,PUT and DELETE requests.But I want not to log GET requests.(Due to Higher number of GET requests).Is there a way to do that?

const mongooseMorgan = require("mongoose-morgan");


app.use(
    mongooseMorgan({
        connectionString: db.url,
    })
);
2

There are 2 answers

0
Tushar Gupta - curioustushar On BEST ANSWER

Use skip

Read - https://github.com/nemanjapetrovic/mongoose-morgan#detailed-usage

app.use(
    mongooseMorgan(
        {
            connectionString: db.url,
        },
        {
           skip: function (req, res) { return req.method === "GET" }
        }
    )
);
0
sb39 On

As per my view, I would prefer to use middlewares. It will save a lot of check and time. Check for the "request.type" and block the request to move further down your code segment.