<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nemanja Petrovic</title>
    <description>The latest articles on Forem by Nemanja Petrovic (@nempet).</description>
    <link>https://forem.com/nempet</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F34855%2F4a5bbc87-fdd2-450f-859a-1adf054bef2a.jpg</url>
      <title>Forem: Nemanja Petrovic</title>
      <link>https://forem.com/nempet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nempet"/>
    <language>en</language>
    <item>
      <title>My first npm package mongoose-morgan</title>
      <dc:creator>Nemanja Petrovic</dc:creator>
      <pubDate>Thu, 28 Sep 2017 21:05:26 +0000</pubDate>
      <link>https://forem.com/nempet/my-first-npm-package-mongoose-morgan-dak</link>
      <guid>https://forem.com/nempet/my-first-npm-package-mongoose-morgan-dak</guid>
      <description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;The package is named &lt;strong&gt;mongoose-morgan&lt;/strong&gt;, here is a &lt;a href="https://www.npmjs.com/package/mongoose-morgan"&gt;link&lt;/a&gt; to it.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;To install it just call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install mongoose-morgan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And to use it with all of its features just add this code into your express app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.use(morgan({
    collection: 'error_logger'
    connectionString: 'mongodb://localhost:27017/logs-db',
    user: 'admin',
    pass: 'test12345'
   },
   {
    skip: function (req, res) {
        return res.statusCode &amp;lt; 400
    }
   },
   'dev'
));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The more important is that you have all available features from morgan package like &lt;strong&gt;format&lt;/strong&gt; and &lt;strong&gt;options&lt;/strong&gt; features, so you can select whatever you want.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>showdev</category>
      <category>npm</category>
      <category>node</category>
    </item>
  </channel>
</rss>
