<?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>DEV Community: Naren</title>
    <description>The latest articles on DEV Community by Naren (@narcotic1998).</description>
    <link>https://dev.to/narcotic1998</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%2F496749%2Fbbd4fdb6-af91-4ef1-b487-3d56f5a2f2c6.jpeg</url>
      <title>DEV Community: Naren</title>
      <link>https://dev.to/narcotic1998</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/narcotic1998"/>
    <language>en</language>
    <item>
      <title>Request parser for Express routes.</title>
      <dc:creator>Naren</dc:creator>
      <pubDate>Mon, 14 Feb 2022 17:29:47 +0000</pubDate>
      <link>https://dev.to/narcotic1998/request-parser-for-express-routes-o6m</link>
      <guid>https://dev.to/narcotic1998/request-parser-for-express-routes-o6m</guid>
      <description>&lt;p&gt;Hello Everyone,&lt;/p&gt;

&lt;p&gt;I always had a difficulty to handle both form data(for file uploads) and JSON within the express routes. So I decided to write a parser, Which will parse the file/JSON inputs from the user and pass it to the Express routes.&lt;/p&gt;

&lt;p&gt;Here's the npm &lt;a href="https://www.npmjs.com/package/@naren_codes/request-parser"&gt;link&lt;/a&gt; for installation and &lt;a href="https://github.com/narcotic1998/request-parser"&gt;repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to try this parser. Any enhancement to this parser or changes to this code is highly appreciated.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>parser</category>
      <category>express</category>
    </item>
    <item>
      <title>API router wrapper for Express node.js</title>
      <dc:creator>Naren</dc:creator>
      <pubDate>Thu, 10 Feb 2022 17:10:53 +0000</pubDate>
      <link>https://dev.to/narcotic1998/api-router-plugin-for-nodejs-41db</link>
      <guid>https://dev.to/narcotic1998/api-router-plugin-for-nodejs-41db</guid>
      <description>&lt;p&gt;Hello everyone 👋, I'm Naren.&lt;/p&gt;

&lt;p&gt;I have developed a plugin to declare express api routes in node js in a easy way.&lt;/p&gt;

&lt;p&gt;Feel free to check it out. Any corrections in plugin is highly appreciated. &lt;/p&gt;

&lt;p&gt;Here's the npm &lt;a href="https://www.npmjs.com/package/@naren_codes/server-router"&gt;link&lt;/a&gt; and brief explanation of the plugin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;



&lt;p&gt;&lt;code&gt;npm i @naren_codes/server-router&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const Router = require("@naren_codes/server-router");

const API_ROUTE = {
     // API url
     path : "user",
     // API method
     method : "get",
     /* Before Enter middleware - called before calling api handler 
        If returned Promise will call next() on resolve and ends api request without calling handler on reject
        If returns nothing calls next() after beforeEnter
        @params - request object
     */
    // Optional
     beforeEnter : (req) =&amp;gt; {
          return Promise.resolve();
     },
     /* Api Handler - should return promise 
        @params - request object
     */
     handler : (req =&amp;gt; {
          return Promise.resolve({
               data : "Hello World", // Response data for the api request
               status : 200, // Send any HTTP statuses
               headers : {
                    // Declare any response header to be binded in the request here
                    "Content-Type" : 'application/json', // Optional by default express will evaluate Content-Type
                    "Cache-Control" : `max-age=1000`
               },
               // Declare any cookies to be set in the client's browser
               cookies : {
                    auth_token : token
               }
          });
     }),
     // Child routes based on current route
     children : [
          {
               // userId will be a Dynamic value
               path : ":userId",
               method : "get"
               // Declare handler, beforeEnter, children
          }
     ]
}

/* @params { app, options }
 * app - app object obtained by called express() middleware
 * options - params to be passed for the router
*/

new Router(app, {
     routes : [
          API_ROUTE
          // other api routes
     ],
     /* For static based compressions and serving index.html on all routes 
      * path - folder containing static files (js/css/html)
      * entry_point - for single page applications html mentioned here will sent to browser for all routes that does not match declared routes
     */
     static : {
          path : path.resolve("./server/public"),
          entry_point : "index.html"
     }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>express</category>
      <category>router</category>
    </item>
  </channel>
</rss>
