<?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: Vinod S R</title>
    <description>The latest articles on Forem by Vinod S R (@vinodsr).</description>
    <link>https://forem.com/vinodsr</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%2F304670%2Faa2f628d-c3d6-4a0a-a480-f10e668a6b8b.jpeg</url>
      <title>Forem: Vinod S R</title>
      <link>https://forem.com/vinodsr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vinodsr"/>
    <language>en</language>
    <item>
      <title>dynamoman – the perfect import-export utility for AWS DynamoDB administration</title>
      <dc:creator>Vinod S R</dc:creator>
      <pubDate>Sun, 22 May 2022 13:05:20 +0000</pubDate>
      <link>https://forem.com/vinodsr/dynamoman-the-perfect-import-export-utility-for-aws-dynamodb-administration-1l6i</link>
      <guid>https://forem.com/vinodsr/dynamoman-the-perfect-import-export-utility-for-aws-dynamodb-administration-1l6i</guid>
      <description>&lt;p&gt;It is quite surprising that AWS didn’t provide an import export support for its popular database DynamoDB. When I started using DynamoDB for my project, I found the unavailability of import export feature hounding me during data migration or copying data between environments.&lt;/p&gt;

&lt;p&gt;This made me to start looking for options for exporting the tables of DynamoDB. I found there are some options must most of them are more than 1 year old and lacks intuitive features. This made me to think about creating a cli which will handle the import export of tables, thus created a new cli – &lt;a href="https://www.npmjs.com/package/dynamoman"&gt;dynamoman &lt;/a&gt;(&lt;a href="https://www.npmjs.com/package/dynamoman"&gt;https://www.npmjs.com/package/dynamoman&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;Easily export the dynamoDB table as JSON&lt;br&gt;
Imports the data into any dynamoDB table&lt;br&gt;
Export from one region and import in to another&lt;br&gt;
Supports batch import (chunks of 25 records)&lt;br&gt;
Supports Windows / Linux / Mac&lt;/p&gt;

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

&lt;p&gt;You can use npm / yarn to install the cli&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g  dynamoman&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To verify the Installation&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dynamoman --help&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;For importing the data use the import command and for exporting use the export command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dynamoman import --file table_dump.json --table &amp;lt;mytable&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;dynamoman export --file output.json --table &amp;lt;mytable&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;More feature are there in the pipeline including&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Export all tables to a zip&lt;/li&gt;
&lt;li&gt;Import all tables from a zip&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you like to contribute to this project, please feel free to submit a pull request @ &lt;a href="https://github.com/vinodsr/dynamoman"&gt;https://github.com/vinodsr/dynamoman&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>How to enable subscription in Apollo Federation with nestJS graphql</title>
      <dc:creator>Vinod S R</dc:creator>
      <pubDate>Sat, 18 Sep 2021 14:01:22 +0000</pubDate>
      <link>https://forem.com/vinodsr/how-to-enable-subscription-in-apollo-federation-with-nestjs-graphql-15nj</link>
      <guid>https://forem.com/vinodsr/how-to-enable-subscription-in-apollo-federation-with-nestjs-graphql-15nj</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I9xtgC_Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vinodsr.com/myblog/wp-content/uploads/2021/07/apollo-federation1.jpg" class="article-body-image-wrapper"&gt;&lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--I9xtgC_Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vinodsr.com/myblog/wp-content/uploads/2021/07/apollo-federation1.jpg"&gt;&lt;/a&gt;&lt;/p&gt;





&lt;h2&gt;NestJS with GraphQL&lt;/h2&gt;

&lt;p&gt;Setting up a graphQL server in nestJS saves 5x-10x of the effort with vanilla nodejs. NestJS uses the standard apollo library for setting up the graphQL. It supports both normal and federation mode. In federation mode, we can setup graphql servers in every microservices, which can be aggregated using a gateway; Just like API-Gateway with REST services. It is a very good technique if you are running microservices and want to separate the responsibility for each service.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NestJS is one of the powerful nodejs framework available as of today. One of the cool features of nestJS is that it allows easy integration with databases, message queues, authentication etc. Further more it allows developers to create application  using nodeJS with in a much stricter, robust and flexible framework like Spring Boot / Angular.&lt;/p&gt;
&lt;p&gt;If you are new to nestJS head over to &lt;a href="https://docs.nestjs.com"&gt;https://docs.nestjs.com&lt;/a&gt; for getting started. This article expects that you have a prior knowledge of setting up and running nestJS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;Contents&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;the problem&lt;/li&gt;
&lt;li&gt;solution&lt;/li&gt;
&lt;li&gt;conclusion&lt;/li&gt;
&lt;li&gt;bonus tip&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id="theproblem"&gt;the problem&lt;/h2&gt;

&lt;p&gt; All this comes with some inherent caveats from the apollo library. While setting up the federation you cannot use graphql subscription. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jEbL7gDK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vinodsr.com/myblog/wp-content/uploads/2021/07/Federation-error-subs-1024x69.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jEbL7gDK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vinodsr.com/myblog/wp-content/uploads/2021/07/Federation-error-subs-1024x69.png" alt=""&gt;&lt;/a&gt;You will probably see this error&lt;/p&gt;

&lt;p&gt;Apollo had come up with an &lt;a href="https://www.apollographql.com/blog/backend/federation/using-subscriptions-with-your-federated-data-graph/" rel="noreferrer noopener"&gt;approach &lt;/a&gt;to over come this problem. But it over complicates the situation. Lets see how to tackle this problem using the features in nestJS. In the example i am using the &lt;a href="https://docs.nestjs.com/graphql/resolvers#schema-first" rel="noreferrer noopener"&gt;schema first approach&lt;/a&gt;. The same approach can be implemented in the &lt;a href="https://docs.nestjs.com/graphql/resolvers#code-first" rel="noreferrer noopener"&gt;code based approach&lt;/a&gt;. &lt;/p&gt;

&lt;h2 id="solution"&gt;solution&lt;/h2&gt;

&lt;p&gt;The solution to this problem is to hide the subscription based schema for the federation server and host the subscription based graphql as a separate normal graphql server. Seems very simple huh ? Not that easy :) . We will cover the method with some simple steps. &lt;/p&gt;

&lt;h4&gt;step 1 : Classify Schema&lt;/h4&gt;

&lt;p&gt;The primary step is to separate your graphql schema in to different files as per the below conventions. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;*.graphq&lt;/strong&gt;l : for graphql syntax supported in both federation and normal mode&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;*.graphql.federation&lt;/strong&gt; : for syntax supported only in federation mode (eg : extends)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;*.graphql.normal&lt;/strong&gt; : for syntax supported only in normal mode (eg : subscription)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Save the subscription model in any "&lt;em&gt;&lt;strong&gt;graphql.normal&lt;/strong&gt;&lt;/em&gt;" file&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9ADSRlOw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vinodsr.com/myblog/wp-content/uploads/2021/07/vscode-formatted.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9ADSRlOw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vinodsr.com/myblog/wp-content/uploads/2021/07/vscode-formatted.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;You can give any name you would like to. This tutorial follows this naming convention.&lt;/p&gt;&lt;/blockquote&gt;

&lt;h4&gt;step 2 : configure server&lt;/h4&gt;

&lt;p&gt;Setup the app.module.ts with two graphql modules, one for the normal server and another for the federation server.  We need to configure the module in such a way that the only federation module loads the &lt;code&gt;&lt;strong&gt;.graphql.federation&lt;/strong&gt;&lt;/code&gt; file and only normal module loads the &lt;code&gt;&lt;strong&gt;graphql.normal&lt;/strong&gt;&lt;/code&gt; file. The &lt;strong&gt;&lt;code&gt;.graphql&lt;/code&gt;&lt;/strong&gt; file has to be loaded by both modules.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;playground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;typePaths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./**/*.{graphql,graphql.normal}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;installSubscriptionHandlers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nx"&gt;GraphQLFederationModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;playground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/graphql-federated&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;typePaths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./**/*.{graphql,graphql.federation}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;Notice that type paths for the two modules are different as per our convention. The normal graphql with subscription is now available at &lt;code&gt;/grapqhl&lt;/code&gt; and the  server for federation gateway is available at &lt;code&gt;/graphql-federated&lt;/code&gt;&lt;/p&gt;





&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;&lt;span&gt;We are not spinning two servers here. Its the same express server with two middleware configured for different paths. So there will not be any performance issues&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt;





&lt;h4&gt;step 3 : the illusion&lt;/h4&gt;





&lt;p&gt;This is the most important step. There are some directives in graphql that only works in the federated mode and vice versa. You will finally end up in writing the custom version of the grapqhl model in the federated and the normal files. This will add the headache of duplicate graphql models in the application.&lt;/p&gt;





&lt;p&gt;This problem can be tackled in a easy way , using dummy directives !&lt;/p&gt;



&lt;p&gt;Define a declarative for “key” in &lt;strong&gt;&lt;em&gt;key.directive.ts&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;SchemaDirectiveVisitor&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apollo-server-express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;GraphQLField&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * This is a dummy implementation of the key directive for the normal mode
 */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;FakeKeyDirective&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;SchemaDirectiveVisitor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/**
   * Fake Key definition
   * @param _field Field of graphql
   */&lt;/span&gt;
  &lt;span class="nx"&gt;visitFieldDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_field&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;GraphQLField&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nx"&gt;lt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nx"&gt;gt&lt;/span&gt;&lt;span class="p"&gt;;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;_field&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Include it in the module (&lt;strong&gt;&lt;em&gt;app.module.ts&lt;/em&gt;&lt;/strong&gt;)&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;GraphQLModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;playground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/graphql&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;typePaths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./**/*.{graphql,graphql.normal}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;installSubscriptionHandlers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

      &lt;span class="na"&gt;directiveResolvers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FakeKeyDirective&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
    &lt;span class="nx"&gt;GraphQLFederationModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;playground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/graphql-federated&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;typePaths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./**/*.{graphql,graphql.federation}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;controllers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppController&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;UsersResolver&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;ul&gt;&lt;li&gt;Define a fake implementation. This only has to work in the normal mode. So the file name has to end with “graphql.normal” say "key.graphql.normal" &lt;/li&gt;&lt;/ul&gt;




&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;directive&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt; &lt;span class="nx"&gt;OBJECT&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;Now you can define the model using the federation supported @key directive and the model works both in federation and normal graphql server. Let's edit "departments.graphql"&lt;/p&gt;




&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Department&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fields&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;thats all folks&lt;/h2&gt;





&lt;p&gt; Now you can start the federation gateway which listens to the the&lt;code&gt; /graphql-federated&lt;/code&gt; and the federation works. &lt;/p&gt;





&lt;p&gt;For subscription you can use any Websocket enabled gateways like nginx, istio etc and connect directly to the microservices&lt;/p&gt;





&lt;h2 id="conclusion"&gt;conclusion&lt;/h2&gt;





&lt;p&gt;Yes it is possible to enable federation and subscription for graphql in nestJS using a simple trick. More efficient than the &lt;a href="https://www.apollographql.com/blog/backend/federation/using-subscriptions-with-your-federated-data-graph/" rel="noreferrer noopener"&gt;Apollo &lt;/a&gt;method. You can download the entire code for your reference from my &lt;a href="https://github.com/vinodsr/nestjs-graphql-federation-with-subscription" rel="noreferrer noopener"&gt;github repo (https://github.com/vinodsr/nestjs-graphql-federation-with-subscription&lt;/a&gt;)&lt;a href="https://github.com/vinodsr/nestjs-graphql-federation-with-subscription" rel="noreferrer noopener"&gt;.&lt;/a&gt;&lt;/p&gt;





&lt;h2 id="bonustip"&gt;bonus tip&lt;/h2&gt;





&lt;p&gt;Since you are using a separate file extension other than .graphql, your IDE won’t give the native graphql formatting for the graphql.normal and graphql.federation files. There is a fix for this. Just enabled file associations for those extensions. &lt;/p&gt;





&lt;p&gt;This is how it looks like in VS Code. Adding the file extensions will give you syntax highlighting and code formatting for the normal and federation graphql. &lt;/p&gt;





&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4PCLR5_Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://vinodsr.com/myblog/wp-content/uploads/2021/07/image-2.png" alt=""&gt;




&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3JOwpme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/vinodsr"&gt;
        vinodsr
      &lt;/a&gt; / &lt;a href="https://github.com/vinodsr/nestjs-graphql-federation-with-subscription"&gt;
        nestjs-graphql-federation-with-subscription
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Sample code showing how to integrate subscription in apollo graphql server using nestJS
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>nestjs</category>
      <category>graphql</category>
      <category>apollo</category>
    </item>
    <item>
      <title>CCTV Object Detection using ML - Part 2 with Pi</title>
      <dc:creator>Vinod S R</dc:creator>
      <pubDate>Sat, 10 Oct 2020 07:44:50 +0000</pubDate>
      <link>https://forem.com/vinodsr/cctv-object-detection-using-ml-part-2-with-pi-glf</link>
      <guid>https://forem.com/vinodsr/cctv-object-detection-using-ml-part-2-with-pi-glf</guid>
      <description>&lt;p&gt;This post is the second part of my experiments with CCTV series. If you hadn't read the first part please read it over &lt;a href="https://dev.to/vinodsr/cctv-object-detection-using-ml-4923"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Mission Pi
&lt;/h1&gt;

&lt;p&gt;After the successful setup of CCTV Object detection in my Laptop, I had decided to implement the feature using my Pi4. Thus achieving 24/7 monitoring under low power consumption ie more savings 💰.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk71cfzn2l374hdo8xx6z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk71cfzn2l374hdo8xx6z.jpg" alt="Raspberry-Pi-4-4GB-Model-B-8"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Took my Pi, installed docker and ran the docker compose as per the frigate documentation. &lt;/p&gt;

&lt;p&gt;But it failed and I understood that the current version of frigate won't work with ARM base. (containers != virtualization) 😡 .&lt;/p&gt;

&lt;p&gt;"Hey Google! Give me some solution"&lt;/p&gt;

&lt;p&gt;This time found a &lt;a href="https://github.com/kpine/frigate" rel="noopener noreferrer"&gt;fork of frigate&lt;/a&gt;, which uses pyarrow image to run the application. But the code base is far behind the actual frigate one. So latest features will be missing if I use this repo. &lt;/p&gt;

&lt;p&gt;The only choice I have is to make my own fork and implement the changes. This also gave me the opportunity to add some features. The original version sends the image and details of an event as separate MQTT message. There is no option to link the two messages (no reference ids) to produce a meaningful output. &lt;/p&gt;

&lt;p&gt;Sat down with the code for 2 hours and came up with a Pi enabled frigate version. You can download and build the image from &lt;a href="https://github.com/vinod/frigate" rel="noopener noreferrer"&gt;my repo&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Changes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Added Raspberry Pi support (Tested in Pi 4)&lt;/li&gt;
&lt;li&gt;Added a new MQTT event (frigate///event) that will hold the event details and snapshot in base64. (schema)[&lt;a href="https://github.com/vinodsr/frigate#frigatecamera_nameobject_nameevent" rel="noopener noreferrer"&gt;https://github.com/vinodsr/frigate#frigatecamera_nameobject_nameevent&lt;/a&gt;]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;During this time I found that my Pi was getting hot &amp;gt; 50 deg. Since the ML process is looking through each frames for identifying the objects it increases the CPU load. I had tweaked the config of frigate, which made the process to look in every 10 frames and this improved the performance and didn't have any problems with the result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    take_frame: 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Uploading my config for your reference(&lt;a href="https://gist.github.com/vinodsr/edabaf37ca8ab77f68688844ff48124e#file-config-yml" rel="noopener noreferrer"&gt;https://gist.github.com/vinodsr/edabaf37ca8ab77f68688844ff48124e#file-config-yml&lt;/a&gt;)&lt;/p&gt;

&lt;h1&gt;
  
  
  The Setup
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/kdiLau77NE9Z8vxGSO/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/kdiLau77NE9Z8vxGSO/giphy.gif" alt="Installation fun"&gt;&lt;/a&gt;&lt;/p&gt;
Don't worry it will be easy :)



&lt;p&gt;You need to install a MQTT server(I am using mosquito since it is light weight), compile and run docker and finally setup home automation to trigger some action on the detection.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Mosquitto
&lt;/h3&gt;

&lt;p&gt;To install the Mosquitto Broker enter these next commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pi@raspberry:~ $ sudo apt update
pi@raspberry:~ $ sudo apt install -y mosquitto mosquitto-clients
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make Mosquitto auto start on boot up enter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pi@raspberry:~ $ sudo systemctl enable mosquitto.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Build Frigate for Pi
&lt;/h3&gt;

&lt;p&gt;Clone my repo&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/vinodsr/frigate.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run docker build&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; docker build -t frigate:rpi -f Dockerfile.rpi .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create docker-compose.yml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: "3.8"
services:
    frigate:
        container_name: frigate
        restart: unless-stopped
        privileged: true
        shm_size: '1g' # should work for 5-7 cameras
        image: frigate:rpi
        volumes:
            - /dev/bus/usb:/dev/bus/usb
            - ./config:/config
            - ./clips:/clips
        ports:
            - "5000:5000"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run docker compose&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you build the docker containers, you can toggle the detection by executing docker stop and start comamnds&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker stop frigate
docker start frigate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Further more you can add this as a cronjob to automate the start the stop&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Paste the content in the editor to start the detection at 10 pm and stop at 6 am&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00 22 * * * docker start frigate
00 06 * * * docker stop frigate

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Automate everthing
&lt;/h3&gt;

&lt;p&gt;I use &lt;a href="https://nodered.org/" rel="noopener noreferrer"&gt;node-red&lt;/a&gt; for home automation. Used MQTT, &lt;a href="https://flows.nodered.org/node/node-red-contrib-telegrambot" rel="noopener noreferrer"&gt;telegram bot&lt;/a&gt; nodes to design the automation. (used botmaster to create a telegram bot. You can read more about it from &lt;a href="https://core.telegram.org/bots#creating-a-new-bot" rel="noopener noreferrer"&gt;here&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Attaching my flow definition for your &lt;a href="https://gist.github.com/vinodsr/edabaf37ca8ab77f68688844ff48124e#file-node-red-flow-sample-json" rel="noopener noreferrer"&gt;reference&lt;/a&gt;. You can import it to your node-red flows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo28fnyyvx0v3pmlmr65k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fo28fnyyvx0v3pmlmr65k.png" alt="node-red flow"&gt;&lt;/a&gt;&lt;br&gt;My node-red flow/figcaption&amp;gt;
 &lt;/p&gt;

&lt;h1&gt;
  
  
  The Result
&lt;/h1&gt;

&lt;p&gt;After I setup the CCTV automation, when someone 🚶 is at my front door, I will get a telegram message. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwqlog5t5xaxbayu35zl0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwqlog5t5xaxbayu35zl0.jpg" alt="Telegram message"&gt;&lt;/a&gt;&lt;/p&gt;
Message from telegram bot


 

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;This wraps up the CCTV using ML series. It was very fun integrating ML to my normal CCTV cameras. The solution that I achieved is 100% safe and secure. No data is being sent to cloud or stored in any third party server. Hope you like my frigate &lt;a href="https://github.com/vinod/frigate" rel="noopener noreferrer"&gt;fork&lt;/a&gt;. See you next time with another home IoT project. &lt;/p&gt;

</description>
      <category>tensorflow</category>
      <category>cctv</category>
      <category>iot</category>
      <category>python</category>
    </item>
    <item>
      <title>CCTV Object Detection using ML</title>
      <dc:creator>Vinod S R</dc:creator>
      <pubDate>Sat, 12 Sep 2020 09:51:54 +0000</pubDate>
      <link>https://forem.com/vinodsr/cctv-object-detection-using-ml-4923</link>
      <guid>https://forem.com/vinodsr/cctv-object-detection-using-ml-4923</guid>
      <description>&lt;p&gt;My CCTV setup always have challenges in terms of motion detection. It simply uses the difference between frames based on a tolerance value and triggers an alert. I need to have a more sophisticated alert mechanism, which can detect person, cat , dog , car etc. But right now i am not going to upgrade the CCTV to a high end system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TpVGJR9N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/aarbsdl3piscmvqhchax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TpVGJR9N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/aarbsdl3piscmvqhchax.png" alt="Google"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Hey google find me a utility which can detect objects from CCTV camera&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;After a  long search i ended up in a github page of frigate. &lt;a href="https://github.com/blakeblackshear/frigate"&gt;https://github.com/blakeblackshear/frigate&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As per the definition in the README.md&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Uses OpenCV and Tensorflow to perform realtime object detection locally for IP cameras. Designed for integration with HomeAssistant or others via MQTT.

* Leverages multiprocessing heavily with an emphasis on realtime over processing every frame
* Uses a very low overhead motion detection to determine where to run object detection
* Object detection with Tensorflow runs in a separate process
* Object info is published over MQTT for integration 
* An endpoint is available to view an MJPEG stream for debugging, but should not be used continuously
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/3XR0chfiSTtAI/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3XR0chfiSTtAI/giphy.gif" alt="Wow"&gt;&lt;/a&gt;&lt;br&gt;
WoW !. This is what i was looking for.&lt;/p&gt;

&lt;p&gt;Wait a second! Did they say IP camera ? All my camera are analog camera connected to HikVision DVR (DS-7B08HUHI-K1). :( &lt;/p&gt;

&lt;p&gt;I didn't give up. Loaded Google and started the search with the query &lt;code&gt;HIKVISION CAMERA STREAM WITHOUT IP CAMERA&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/gf5lHEzYVU8DoVVlhs/source.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/gf5lHEzYVU8DoVVlhs/source.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After hours of searching. I found that HikVision have the capability to share the rtsp stream of any camera even though non-ip camera. &lt;/p&gt;

&lt;p&gt;You need to connect the DVR to your network using a LAN cable&lt;br&gt;
Once it is configured, then the rtsp stream is available at &lt;br&gt;
&lt;code&gt;rtsp://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@&amp;lt;ip of the DVR&amp;gt;:554/Streaming/channels/&amp;lt;x&amp;gt;0&amp;lt;y&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;where username and password is same as that you use to login to the CCTV console,&lt;br&gt;
x is the camera number&lt;br&gt;
y can be 1 or 2. 2 will be a low quality stream and 1 will be a high quality stream. &lt;/p&gt;

&lt;p&gt;eg : &lt;br&gt;
&lt;code&gt;rtsp://&amp;lt;username&amp;gt;:&amp;lt;password&amp;gt;@&amp;lt;ip of the DVR&amp;gt;:554/Streaming/channels/102&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So now i have a IP camera stream. So back to the setup of frigate. &lt;/p&gt;

&lt;p&gt;It is very simple. You need to install docker. Head over to the docker.com to install docker in your machine. (&lt;a href="https://docs.docker.com/get-docker/"&gt;https://docs.docker.com/get-docker/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;You can then follow the steps mentioned in the github page (&lt;a href="https://github.com/blakeblackshear/frigate#getting-started"&gt;https://github.com/blakeblackshear/frigate#getting-started&lt;/a&gt;). &lt;/p&gt;

&lt;p&gt;You can also tweak the &lt;code&gt;config.yml&lt;/code&gt; for your preference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    ################
    # Camera level object config. This config is merged with the global config above.
    ################
    objects:
      track:
        - person
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use this section to tell frigate about the object that needs to be tracked. By default it tracks person. You can add cats, dog etc. The available objects that can be tracked by default can be found at (&lt;a href="https://dl.google.com/coral/canned_models/coco_labels.txt"&gt;https://dl.google.com/coral/canned_models/coco_labels.txt&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;If you setup a MQTT broker like mosquitto (&lt;a href="https://mosquitto.org/"&gt;https://mosquitto.org/&lt;/a&gt;), then frigate will send events on each detection to the broker. You can use this for automation. &lt;/p&gt;

&lt;p&gt;Make sure you give the rtsp link of the camera correctly and the camera name is correct. &lt;/p&gt;

&lt;p&gt;If everything is done correctly, you can start the docker and the site will be available @ port 5000&lt;/p&gt;

&lt;p&gt;Load &lt;a href="http://localhost:5000/"&gt;http://localhost:5000/&lt;/a&gt; to see the debug stream of the camera with object recognition. &lt;br&gt;
&lt;code&gt;As per the author the debug stream can reduce the performance of the program&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once a person is in front of the camera, you will see something like this in the debug stream, also an event will be published in the MQTT server, which can be used to trigger some message or anything. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kvv8fmfk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kjg7karvn97eituezz90.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kvv8fmfk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kjg7karvn97eituezz90.jpg" alt="Debug Stream"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Next Steps
&lt;/h1&gt;

&lt;p&gt;My next step is to integrate this with my home automation to trigger a message on my phone with the picture. Also to run this on raspberry pi, since the original version doesn't support pi.&lt;/p&gt;

&lt;p&gt;I will be back once it is ready. Till then take care bye.&lt;/p&gt;

&lt;p&gt;Read the second part of the blog &lt;a href="https://dev.to/vinodsr/cctv-object-detection-using-ml-part-2-with-pi-glf"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tensorflow</category>
      <category>cctv</category>
      <category>python</category>
      <category>iot</category>
    </item>
    <item>
      <title>NestJS :  a backend nodeJS framework for the enterprise</title>
      <dc:creator>Vinod S R</dc:creator>
      <pubDate>Thu, 09 Jan 2020 08:47:04 +0000</pubDate>
      <link>https://forem.com/vinodsr/nestjs-a-backend-nodejs-framework-for-the-enterprise-40m6</link>
      <guid>https://forem.com/vinodsr/nestjs-a-backend-nodejs-framework-for-the-enterprise-40m6</guid>
      <description>&lt;p&gt;Last week an idea stuck my mind to explore the frameworks available in nodeJS ecosystem to develop backend API, which is scalable and efficient. I was using expressJS long time for my projects. It's time to think about the &lt;code&gt;alternate future&lt;/code&gt; 😃.&lt;/p&gt;

&lt;p&gt;I started listing down all the features that would be required for a good nodeJS backend framework (purely based on my understanding).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modularity&lt;/li&gt;
&lt;li&gt;Easy to develop&lt;/li&gt;
&lt;li&gt;Integration with other applications&lt;/li&gt;
&lt;li&gt;Extensibility&lt;/li&gt;
&lt;li&gt;Maintainable&lt;/li&gt;
&lt;li&gt;Performance&lt;/li&gt;
&lt;li&gt;Easy to test and deploy&lt;/li&gt;
&lt;li&gt;DevOps support ready&lt;/li&gt;
&lt;li&gt;Support for microservices&lt;/li&gt;
&lt;li&gt;REST &amp;amp; GraphQL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I took my special analyser googles, fuelled up my &lt;code&gt;Time Machine&lt;/code&gt; and started my journey to future in search for my query. Went through frameworks like express, Koa, hapi,  molecular, Seneca etc. But none had full-filled my need, until i saw &lt;a href="https://nestjs.com" rel="noopener noreferrer"&gt;NestJS&lt;/a&gt;. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Nest (NestJS) is a futuristic framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming). It is build on top of typescript (javascript version is also available). The framework is built by taking the concepts of Angular  putting it on top of &lt;a href="https://expressjs.com/" rel="noopener noreferrer"&gt;expressJS&lt;/a&gt; or &lt;a href="https://www.fastify.io/" rel="noopener noreferrer"&gt;fastify&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes you heard it right. I can change the underlying core framework to either express or fastify without changing any API code. Fastify has got proven track record when it comes to performance. &lt;/p&gt;

&lt;p&gt;Let's have a look in to how you can setup the nestJS framework. &lt;/p&gt;

&lt;h2&gt;
  
  
  Chapters ahead
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Installation&lt;/li&gt;
&lt;li&gt;First API&lt;/li&gt;
&lt;li&gt;Exception handling&lt;/li&gt;
&lt;li&gt;Guards&lt;/li&gt;
&lt;li&gt;Microservices Support&lt;/li&gt;
&lt;li&gt;GraphQL&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.toexpress-fastify-"&gt;Express/Fastify&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;More goodies&lt;/li&gt;
&lt;li&gt;Wrapping up&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;

&lt;p&gt;The installation is pretty much straight forward. You can use npm/yarn to install the framework.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-g&lt;/span&gt; @nestjs/cli
nest new my-first-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cli will ask for the type of package system you want (npm/yarn). &lt;br&gt;
Once the installation is complete you can start the application using the start script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;my-first-project
npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open any browser and try &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;. You will now see the "Hello World!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fpn0c9koasnkvjxje20ox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fpn0c9koasnkvjxje20ox.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hurray!&lt;/p&gt;

&lt;p&gt;You can also use &lt;code&gt;npm run start&lt;/code&gt; to start in the application in dev mode. This will watch for any changes in the code and restart the application.&lt;/p&gt;

&lt;h1&gt;
  
  
  First API
&lt;/h1&gt;

&lt;p&gt;In most of the nodeJS backend framework, for writing a API, we will create a callback method for the defined URL. This is not followed in nestJS. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you have a Angular/Spring boot background, you will find the below features very similar to Angular/Spring boot&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In nestJS, in order to create an API we need a controller which is similar to a component in Angular (or a RestController in Springboot).&lt;/p&gt;

&lt;p&gt;Let's say i need to create a time api which returns the current server time.&lt;/p&gt;

&lt;p&gt;Run the following cli command inside your project directory to create a new controller&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nest g controller &lt;span class="nb"&gt;time&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Where time is our controller name&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This will create two files. The time.controller.spec.ts is the test file and time.controller.ts is our main file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;CREATE /src/time/time.controller.spec.ts &lt;span class="o"&gt;(&lt;/span&gt;479 bytes&lt;span class="o"&gt;)&lt;/span&gt;
CREATE /src/time/time.controller.ts &lt;span class="o"&gt;(&lt;/span&gt;97 bytes&lt;span class="o"&gt;)&lt;/span&gt;
UPDATE /src/app.module.ts &lt;span class="o"&gt;(&lt;/span&gt;322 bytes&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that it updates the &lt;code&gt;app.module.ts&lt;/code&gt; file to add the reference to the  new controller &lt;code&gt;time.controller&lt;/code&gt;. This is similar to bootstrapping a component in Angular.&lt;/p&gt;

&lt;p&gt;This is how the folder structure looks after you create a controller.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fh92prpoiodafpjerdd9f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fh92prpoiodafpjerdd9f.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open the time.controller.ts and replace the code with the below code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Controller&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Get&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Controller&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;time&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TimeController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Get&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;time&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the application (If you had started in dev mode, it will restart automatically) and access &lt;a href="http://localhost:3000/time" rel="noopener noreferrer"&gt;http://localhost:3000/time&lt;/a&gt; using postman / browser / curl&lt;/p&gt;

&lt;p&gt;You will now see the below response as json.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"time"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2019-12-31T05:06:31.805Z"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you gave an argument in the &lt;code&gt;@Get&lt;/code&gt; decorator then the API url will change accordingly. &lt;/p&gt;

&lt;p&gt;So the effective url of an API =  + @Controller's url + @Get's url&lt;/p&gt;

&lt;p&gt;Similar to @Get, NestJs also supports other REST verb like &lt;a class="mentioned-user" href="https://dev.to/post"&gt;@post&lt;/a&gt;, @Put, @Update, @Delete etc..&lt;/p&gt;

&lt;p&gt;What ever object is returned from the method is sent back to the client as the result of the API. &lt;/p&gt;

&lt;p&gt;You can get more details about the controller implementation @ &lt;a href="https://docs.nestjs.com/controllers" rel="noopener noreferrer"&gt;https://docs.nestjs.com/controllers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is one of the simplest API implementation in nodeJS, similar to Java's Spring boot implementation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Exception handling
&lt;/h1&gt;

&lt;p&gt;In nodeJS we use try/catch or exception middleware to handle the errors in the application. &lt;/p&gt;

&lt;p&gt;But in NestJS, the approach is unique. &lt;/p&gt;

&lt;p&gt;You can create a filter class that can handle the specific exceptions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ExceptionFilter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Catch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ArgumentsHost&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;HttpException&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Response&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;HttpException&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HttpExceptionFilter&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;ExceptionFilter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;exception&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HttpException&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ArgumentsHost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;switchToHttp&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getResponse&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getRequest&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;exception&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getStatus&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nx"&gt;response&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means if an HttpException is thrown from any part of the application, this filter is triggered, the logic executes and a response is sent back to the client. &lt;/p&gt;

&lt;p&gt;Easy ? uh ?&lt;/p&gt;

&lt;p&gt;More details @ &lt;a href="https://docs.nestjs.com/exception-filters" rel="noopener noreferrer"&gt;https://docs.nestjs.com/exception-filters&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Guards
&lt;/h1&gt;

&lt;p&gt;Security is very critical. Typically in a expressJS application we use middleware to check for the auth level of an API.&lt;/p&gt;

&lt;p&gt;In nestJS we can use guards for this purpose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CanActivate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ExecutionContext&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RolesGuard&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;CanActivate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;canActivate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ExecutionContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Observable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and in the controller&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Controller&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cats&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;UseGuards&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;RolesGuard&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CatsController&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also create global guards in &lt;code&gt;app.module.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;NestFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AppModule&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;useGlobalGuards&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RolesGuard&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Microservices Support
&lt;/h1&gt;

&lt;p&gt;One of the biggest advantage of this framework is it's out of the box support for microservices and transport layers. It has got the support for different transport layers like TCP, gRPC, MQTT, RabbitMQ etc...&lt;/p&gt;

&lt;p&gt;You can read more about microservices @ &lt;a href="https://docs.nestjs.com/microservices/basics" rel="noopener noreferrer"&gt;https://docs.nestjs.com/microservices/basics&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  GraphQL
&lt;/h1&gt;

&lt;p&gt;NestJS has got out of the box support for GraphQL. It starts with installing the GraphQL support package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;--save&lt;/span&gt; @nestjs/graphql apollo-server-express graphql-tools graphql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NestJS offers two methods of integrating GraphQL. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Schema first : where the definition is written in GraphQL Schema Definition Language (SDL)&lt;/li&gt;
&lt;li&gt;Code first: where we use decorators to generate the GraphQL schema&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can read more about GraphQL integration @ &lt;a href="https://docs.nestjs.com/graphql/quick-start" rel="noopener noreferrer"&gt;https://docs.nestjs.com/graphql/quick-start&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Express / Fastify ?
&lt;/h1&gt;

&lt;p&gt;Another impressive feature of NestJS is that, it can run on top of express or fastify frameworks. You don't have to change you API's code for that. If you want to access any native framework features of epxress / fastify, it is possible. &lt;/p&gt;

&lt;p&gt;By default NestJS uses express framework. If you want to use fastify framework, then you can install the package for fastify.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;--save&lt;/span&gt; @nestjs/platform-fastify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed you need to modify the module.ts with the below code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NestFactory&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;FastifyAdapter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;NestFastifyApplication&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@nestjs/platform-fastify&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApplicationModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./app.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;NestFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;NestFastifyApplication&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;ApplicationModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;FastifyAdapter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your application is ready for fastify. &lt;/p&gt;

&lt;p&gt;Benchmark results shows that fastify has got more performance than express&lt;/p&gt;

&lt;h1&gt;
  
  
  More goodies
&lt;/h1&gt;

&lt;p&gt;Further more it has got out of the box support for &lt;a href="https://docs.nestjs.com/recipes/swagger" rel="noopener noreferrer"&gt;Swagger&lt;/a&gt;, &lt;a href="https://docs.nestjs.com/fundamentals/testing" rel="noopener noreferrer"&gt;Jest&lt;/a&gt;, &lt;a href="https://docs.nestjs.com/fundamentals/testing" rel="noopener noreferrer"&gt;Supertest&lt;/a&gt;, &lt;a href="https://docs.nestjs.com/recipes/sql-typeorm" rel="noopener noreferrer"&gt;TypeORM&lt;/a&gt;, &lt;a href="https://docs.nestjs.com/recipes/sql-sequelize" rel="noopener noreferrer"&gt;Sequelize&lt;/a&gt;, &lt;a href="https://docs.nestjs.com/recipes/terminus" rel="noopener noreferrer"&gt;Terminus&lt;/a&gt;, &lt;a href="https://docs.nestjs.com/recipes/documentation" rel="noopener noreferrer"&gt;Compodoc&lt;/a&gt;, &lt;a href="https://docs.nestjs.com/custom-decorators" rel="noopener noreferrer"&gt;Custom decorators&lt;/a&gt; and lots more...&lt;/p&gt;

&lt;h1&gt;
  
  
  Wrapping up
&lt;/h1&gt;

&lt;p&gt;IMHO &lt;a href="https://nestjs.com" rel="noopener noreferrer"&gt;NestJS&lt;/a&gt; is a framework which can be used in small backend applications to large enterprise level application. It helps you in building an efficient, scalable application. The maintainability of this framework is huge compared to other nodeJS framework. I had seen projects using expressJS where the code maintainability has become a serious concern after some months of development. The ability to switch express and fastify is one of the cool features of NestJS. &lt;/p&gt;

&lt;p&gt;Head on to &lt;a href="https://nestjs.com" rel="noopener noreferrer"&gt;https://nestjs.com&lt;/a&gt; to start developing your app.&lt;/p&gt;

&lt;p&gt;Happy Coding 👍. &lt;/p&gt;

</description>
      <category>node</category>
      <category>frameworks</category>
      <category>nestjs</category>
    </item>
  </channel>
</rss>
