loading...

My first npm package mongoose-morgan

nempet profile image Nemanja Petrovic ・Updated on ・1 min read

Hi,

Recently I was working on one of my express app projects, and I had a need to log all data from morgan npm package to the database. So I found out there are some npm packages available to do it, but I had to create one of my own.

The package is named mongoose-morgan, here is a link to it.

So mongoose-morgan is an npm package express middleware which is combining mongoose and morgan packages by adding an additional functionality to log morgan data into MongoDB.

To install it just call:

npm install mongoose-morgan

And to use it with all of its features just add this code into your express app.

app.use(morgan({
    collection: 'error_logger'
    connectionString: 'mongodb://localhost:27017/logs-db',
    user: 'admin',
    pass: 'test12345'
   },
   {
    skip: function (req, res) {
        return res.statusCode < 400
    }
   },
   'dev'
));

The more important is that you have all available features from morgan package like format and options features, so you can select whatever you want.

Discussion

pic
Editor guide
Collapse
davedodea profile image
Dave O'Dea

Awesome job, @nempet ! This is very useful - super quick way to store application data to MongoDB :)

Collapse
nempet profile image
Nemanja Petrovic Author

Thank you so much! I hope it saves you our most valuable resource - time!

Collapse
danieljsummers profile image
Daniel J. Summers

I recently published my first package to npm as well - it's a rush, isn't it? :) Congratulations!

Collapse
nempet profile image
Nemanja Petrovic Author

Thanks, congratulations to you too.

Yeah, it's a great feeling knowing someone is using your npm package :D