<?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: Arpan Kc</title>
    <description>The latest articles on DEV Community by Arpan Kc (@nipeshkc7).</description>
    <link>https://dev.to/nipeshkc7</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%2F37679%2Fcafa4d43-6112-4586-b4b0-82be42d5fe15.png</url>
      <title>DEV Community: Arpan Kc</title>
      <link>https://dev.to/nipeshkc7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nipeshkc7"/>
    <language>en</language>
    <item>
      <title>DynamoDB: the basics</title>
      <dc:creator>Arpan Kc</dc:creator>
      <pubDate>Tue, 02 Jun 2020 04:09:36 +0000</pubDate>
      <link>https://dev.to/nipeshkc7/dynamodb-the-basics-360g</link>
      <guid>https://dev.to/nipeshkc7/dynamodb-the-basics-360g</guid>
      <description>&lt;p&gt;Recently I've started looking at Serverless architecture inorder to move away from the monolithic architecture. While exploring AWS free tier, Amazon DynamoDB stood out to me. As a NOSQL database with free 25 GB of storage, I could use it for my personal projects basically for free.&lt;/p&gt;

&lt;p&gt;So I've been reading up on AWS docs on the basics of DynamoDB, below listed are some of the basic terminology I have gotten to know about DynamoDB:&lt;/p&gt;

&lt;h3&gt;
  
  
  Tables
&lt;/h3&gt;

&lt;p&gt;Strange name, given DynamoDB is NoSQL, However, it serves as a good mental model, and helps understand how data is grouped together. These 'tables' consists of a collection of 'items'.&lt;/p&gt;

&lt;h3&gt;
  
  
  Items
&lt;/h3&gt;

&lt;p&gt;Items can be thought of as 'rows' in the tables, But unlike traditional tables, it does not have or need a specific schema. Aside from the primary key, it can contain any number of 'key-value' relations, and can also store nested objects upto 32 levels deep. &lt;/p&gt;

&lt;h3&gt;
  
  
  Primary Key
&lt;/h3&gt;

&lt;p&gt;This is a simple one, Primary key uniquely identifies the 'item' in the table, it can be a single attribute or a combination of attributes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Putting it all together
&lt;/h4&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%2Fdocs.aws.amazon.com%2Famazondynamodb%2Flatest%2Fdeveloperguide%2Fimages%2FHowItWorksPeople.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%2Fdocs.aws.amazon.com%2Famazondynamodb%2Flatest%2Fdeveloperguide%2Fimages%2FHowItWorksPeople.png" alt="Dynamo DB table"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The image above is from &lt;a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.TablesItemsAttributes" rel="noopener noreferrer"&gt;AWS docs&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this specific case, 'People' is the table, which consists of a collection of items, And 'PersonID' is the primary key which uniquely identifies the item. Here, besides 'PersonID', other key value attributes can be anything, even nested items.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;So AWS DynamoDB is an awesome free data storage option, however NoSQL Databases has its own use cases as does Relational Databases. So it is important to figure out what kind of storage option is best for your specific project before going forward.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. Please follow me on twitter &lt;a href="https://twitter.com/Nipeshkc7" rel="noopener noreferrer"&gt;@Nipeshkc7&lt;/a&gt;&lt;/em&gt; &lt;/p&gt;

</description>
      <category>aws</category>
      <category>dynamodb</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How I've been misusing Async Await</title>
      <dc:creator>Arpan Kc</dc:creator>
      <pubDate>Mon, 18 May 2020 03:27:27 +0000</pubDate>
      <link>https://dev.to/nipeshkc7/how-i-ve-been-misusing-async-await-1f5j</link>
      <guid>https://dev.to/nipeshkc7/how-i-ve-been-misusing-async-await-1f5j</guid>
      <description>&lt;p&gt;Async-await is very intuitive and apparently very easy to misuse. Recently I've found out how I've been misusing this feature because of which my JS executes a lot slower than it should. &lt;/p&gt;

&lt;p&gt;Let's look at the example to demonstrate what the problem was:&lt;/p&gt;

&lt;h2&gt;
  
  
  How I used to do it:
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Fetching promises one after the other, blocking execution&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;()&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;itemA&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;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://url.com/itemA&lt;/span&gt;&lt;span class="dl"&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;itemB&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;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://url.com/itemB&lt;/span&gt;&lt;span class="dl"&gt;"&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="nx"&gt;itemA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;itemB&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;h2&gt;
  
  
  How the pros do it:
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Fetching multiple promises concurrently to avoid delaying program&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="p"&gt;()&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;itemA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://url.com/itemA&lt;/span&gt;&lt;span class="dl"&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;itemB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://url.com/itemB&lt;/span&gt;&lt;span class="dl"&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;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;all&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;itemA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;itemB&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;items&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;See the core difference is how I was previously waiting for itemA to resolve before fetching itemB. On the other hand, when I wait for both the promises to resolve concurrently I speed up the execution by not having itemA to resolve before itemB.&lt;/p&gt;

&lt;p&gt;(Note: However this is only recommended when the itemB does not somehow depend upon the promise from itemA being resolved first.)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. Please follow me on twitter, I'd really appreciate it. &lt;a href="https://twitter.com/NipeshKc7"&gt;@Nipeshkc&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>asyncawait</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Deploying VueJS Front-end to Netlify</title>
      <dc:creator>Arpan Kc</dc:creator>
      <pubDate>Mon, 27 Apr 2020 06:24:45 +0000</pubDate>
      <link>https://dev.to/nipeshkc7/deploying-vuejs-front-end-to-netlify-322c</link>
      <guid>https://dev.to/nipeshkc7/deploying-vuejs-front-end-to-netlify-322c</guid>
      <description>&lt;p&gt;To preface, I'm currently working on a project whose backend API service I've recently published to heroku. So next step is to deploy my front-end. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Netlify?
&lt;/h2&gt;

&lt;p&gt;Considering all the free options, I settled on Netlify. In addition to the Continuous deployments which let me deploy on every pull request, I also did not have to deal with any server side stuff. And unlike the Heroku free servers, Netlify (static)sites never sleep. &lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying in 3 simple steps
&lt;/h2&gt;

&lt;p&gt;Here's how I did it in 3 simple steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Added a netlify.toml in the root directory which consists of:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   [build]
     command = "npm run build"
     publish="dist"
     base = "client"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the front-end vuejs code is inside the 'client' subdirectory, I have to specify in this .toml file that the subdirectory to use is 'client' and the directory to publish after building is ./dist.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Added a _redirects file inside the /public directory inside client sub-directory.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   /*    /index.html   200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Include this file so that directly going to a different url (like &lt;br&gt;
   &lt;a href="https://yoururl.netlify.app/home"&gt;https://yoururl.netlify.app/home&lt;/a&gt;) won't return a '404')&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Login to netlify and add a new site from git. Then select the repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And voila, netlify should build and deploy the site. &lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

&lt;p&gt;Project Repo: &lt;a href="https://github.com/nipeshkc7/BeatingBookies"&gt;https://github.com/nipeshkc7/BeatingBookies&lt;/a&gt;&lt;br&gt;
Live project: &lt;a href="https://beatingbookies.netlify.app/"&gt;https://beatingbookies.netlify.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. Please follow me on twitter, I'd really appreciate it. &lt;a href="https://twitter.com/NipeshKc7"&gt;@Nipeshkc&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>netlify</category>
      <category>vue</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Deploying Node.js App to Heroku using Github Actions</title>
      <dc:creator>Arpan Kc</dc:creator>
      <pubDate>Mon, 06 Apr 2020 00:04:10 +0000</pubDate>
      <link>https://dev.to/nipeshkc7/deploying-node-js-app-to-heroku-using-github-actions-3k7g</link>
      <guid>https://dev.to/nipeshkc7/deploying-node-js-app-to-heroku-using-github-actions-3k7g</guid>
      <description>&lt;p&gt;Recently I started a project which was basically a Bet-tracking application with Node.js backend and Vue.js Frontend and Sqlite as the database. Initially I had planned on finishing the core functionality early and iterating often. So to do that, I decided to setup a CI/CD pipeline so that I could automate the testing and deployment. In this article I will talk about how I managed to setup a pipeline to automatically test and deploy my Node.js backend to Heroku using Github actions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Initial Folder structure
&lt;/h3&gt;

&lt;p&gt;So this is how my folder structure looks like (Hid other files for simplicity):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Client    //Vue App
- Server    //NodeJs App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Server consists of a Node.js server and Client consists of a VueJs app that sends API requests to the Server for CRUD functionality.&lt;/p&gt;

&lt;p&gt;So in development environment this is how I would run my server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd server;
node index.js;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting Up Deployment pipeline
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Creating a new deploy.yml file inside .github/workflows inside the root folder so the folder structure now looks like this:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- .github/workflows/deploy.yml
- Client    //Vue App
- Server    //NodeJs App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Get Heroku API key using the Heroku command line tool. Running the following command:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku authorizations:create
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add the following Github secrets in your github repo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HEROKU_API_KEY&lt;/li&gt;
&lt;li&gt;HEROKU_APP_NAME&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside the deploy.yml I add the following:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:

  deploy:
      name: Deploy
      runs-on: ubuntu-latest

      steps: 
        - name: Checkout
          uses: actions/checkout@v1

        - name: Add remote origin
          run: git remote add heroku https://heroku:${{ secrets.HEROKU_API_KEY }}@git.heroku.com/${{ secrets.HEROKU_APP_NAME }}.git

        - name: Deploy backend to heroku
          run: git push --force heroku `git subtree split --prefix server HEAD`:master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To break everything down, here is how this yml file works: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runs every pull request OR push to the repo.&lt;/li&gt;
&lt;li&gt;Uses a pre-existing action called 'checkout' &lt;/li&gt;
&lt;li&gt;Runs a job we named 'deploy' which adds a new remote heroku git repository &lt;/li&gt;
&lt;li&gt;This command pushes the 'server' folder to heroku which contains our Node.js application:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push --force heroku `git subtree split --prefix server HEAD`:master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The pipeline is setup, so basically now we have pushed the repo's server folder into heroku, Now we have to instruct heroku on how to handle the application. Before that add a ecosystem.config.js file inside the server folder which contains the following:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;apps&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;matched-betting-tracker&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;instances&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;max&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;NODE_ENV&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;development&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="na"&gt;env_production&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;NODE_ENV&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;production&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Define the start script inside the package.json of our server Node.js application.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;
   &lt;span class="c1"&gt;// Other scripts&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;heroku-prebuild&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;npm install pm2 -g&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;start&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pm2-runtime start ecosystem.config.js --env production&lt;/span&gt;&lt;span class="dl"&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 tells Heroku to install pm2 (which runs our nodejs app in production) before building the app and uses the 'start' script to run the application.&lt;/p&gt;

&lt;p&gt;So next time you push to  your repo, it should be automatically deployed to Heroku.&lt;/p&gt;

&lt;p&gt;Feedbacks appreciated !&lt;/p&gt;

&lt;p&gt;If you are interested in my current project, here's a link to my repo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.github.com/nipeshkc7/matched-betting-tracker"&gt;Matched-betting-tracker&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's a link to an article where I write about implementing OAuth2.0 on my app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/nipeshkc7/oauth-2-0-with-google-api-in-node-js-48m1"&gt;OAuth 2.0 with Google API in Node.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;P.S. Please follow me on twitter, I'd really appreciate it. &lt;a href="https://twitter.com/NipeshKc7"&gt;@Nipeshkc&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>heroku</category>
      <category>devops</category>
      <category>github</category>
    </item>
    <item>
      <title>Organizing my NodeJS code and folder structure</title>
      <dc:creator>Arpan Kc</dc:creator>
      <pubDate>Sun, 02 Feb 2020 13:18:25 +0000</pubDate>
      <link>https://dev.to/nipeshkc7/organizing-my-nodejs-code-and-folder-structure-1060</link>
      <guid>https://dev.to/nipeshkc7/organizing-my-nodejs-code-and-folder-structure-1060</guid>
      <description>&lt;p&gt;As I look at other people's nodeJS repository, I see neatly organized code and folder structure by people who seem like they really know what they're doing. Meanwhile I look at mine, it's a mess. As convenient as it might be to not having keeping everything in a single file, it's not the best practice. So I set on mission to perfectly organize my folder structure. &lt;/p&gt;

&lt;p&gt;To do that, I went through a bunch of other people's repositories, read a bunch of articles and basically what I learned was there is no one-size-fits-all approach. However in my case, I did end up with a folder structure that I think will make my code somewhat maintainable. &lt;/p&gt;

&lt;p&gt;In case of my project, I'm doing a full stack javascript application with vuejs at the front-end and nodejs at the backend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App folder:
-&amp;gt;client (consists of the client side VueJS)
-&amp;gt;server
    ---&amp;gt;controllers
    ---&amp;gt;routes
    ---&amp;gt;models 
    ---services
    ---&amp;gt;helpers
    ---&amp;gt;server.js (app entry point)
-&amp;gt;.env / . git (and other stuff)

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

&lt;/div&gt;



&lt;p&gt;Here I'm only focusing on the server side nodejs. The main components are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;services: consists of methods that does the CRUD(Create Read Update Delete) dirty work&lt;/li&gt;
&lt;li&gt;controllers: takes user request (HTTP requests in our case) and tells the services what to do&lt;/li&gt;
&lt;li&gt;models: represents the database schema&lt;/li&gt;
&lt;li&gt;routes : were done using express to connect urls (user's get and post requests) to controllers&lt;/li&gt;
&lt;li&gt;helpers: Although there is no clear cut definition in terms of javascript, according to people programming in Java helpers are basically a bunch of functions that help in the internal working of the app, but do not directly serve the user's requests. So it would be safe to assume that it would do the same in Javascript.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So this is how you can organize you Nodejs folder structure for your project.&lt;/p&gt;

&lt;p&gt;Thanks for reading and would would love to hear any insights into this matter.&lt;/p&gt;

&lt;p&gt;Follow me on Twitter: &lt;a href="https://twitter.com/NipeshKc7"&gt;@Nipeshkc&lt;/a&gt;*&lt;/p&gt;

&lt;p&gt;Visit my blog: &lt;a href="https://blog.arpankc.com"&gt;blog.arpankc.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>beginners</category>
      <category>folderstructure</category>
      <category>organization</category>
    </item>
    <item>
      <title>OAuth 2.0 with Google API in Node.js</title>
      <dc:creator>Arpan Kc</dc:creator>
      <pubDate>Fri, 31 Jan 2020 11:45:03 +0000</pubDate>
      <link>https://dev.to/nipeshkc7/oauth-2-0-with-google-api-in-node-js-48m1</link>
      <guid>https://dev.to/nipeshkc7/oauth-2-0-with-google-api-in-node-js-48m1</guid>
      <description>&lt;p&gt;With all the asyncs and the chainings and all the other JS shamaladingdongs , doing even simple tasks in Javascript can feel overwhelming, at least for a beginner like me.&lt;/p&gt;

&lt;p&gt;To preface, I'm currently working on my own application which is a simple Match betting tracker to keep track of my bets, and decided to add in OAuth authentication in the app. Because why not. &lt;/p&gt;

&lt;p&gt;The first thing I did was set up an account in Google console, and got me some shiny new credentials (client ID and client Secret) for OAuth 2.0.&lt;/p&gt;

&lt;p&gt;I had trouble getting my head around the authentication flow with all the tokens and secrets and all that. But digging deep, it was quite simple actually and started to appreciate how google makes the process so simple and dare I say, elegant.&lt;/p&gt;

&lt;p&gt;The first thing I did was get the google api:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="nx"&gt;googleapis&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the actual program: &lt;br&gt;
initialized the api library and setup googleConfigs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;google&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;googleapis&lt;/span&gt;&lt;span class="dl"&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;oauth2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;oauth2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;v2&lt;/span&gt;&lt;span class="dl"&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;Oauth2Client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OAuth2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GOOGLE_CLIENT_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GOOGLE_CLIENT_SECRET&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;GOOGLE_REDIRECT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// this must match your google api settings&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;


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



&lt;p&gt;So basically all I had to do was these 3 things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;get a Redirect url for the clients&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The url also contains a code which then I use to get a token ( if the user signs in to their google account that is)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And finally I use the token to get the user details &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getConnectionUrl&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Oauth2Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;generateAuthUrl&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;access_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;offline&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;consent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;defaultScope&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//Call this function somewhere in the program to get URL:&lt;/span&gt;
&lt;span class="c1"&gt;//const url = getConnectionUrl();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Step 2 and 3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getUserDetails&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Oauth2Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;//use code to get the token&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;tokens&lt;/span&gt; &lt;span class="p"&gt;})&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;Oauth2Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setCredentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;     &lt;span class="c1"&gt;//add token to the Oauth credentials&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&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="nx"&gt;oauth2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userinfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Oauth2Client&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;  &lt;span class="c1"&gt;// get userinfo with the newly updated credentials&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 so in the main program , I got a connection url using getConnectionUrl() which then gave me the code in the url which I passed on to getUserDetails() to get the user details.&lt;/p&gt;

&lt;p&gt;So this is how I got OAuth authentication working in my application.&lt;/p&gt;

&lt;p&gt;Thanks for reading. Would appreciate feedbacks. &lt;/p&gt;

&lt;p&gt;If you want to check out my repo, here's the link :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/nipeshkc7/matched-betting-tracker"&gt;Matched-betting-tracker&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please star it, if you like it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. Please follow me on twitter, I'd really appreciate it. &lt;a href="https://twitter.com/NipeshKc7"&gt;@Nipeshkc&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt; *UPDATE*&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Using async-await steps 2 and 3 can be reduced to ::&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;getUserDetails&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&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="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;tokens&lt;/span&gt;&lt;span class="p"&gt;}&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;Oauth2Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nx"&gt;Oauth2Client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setCredentials&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tokens&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;usr_info&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;oauth2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userinfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Oauth2Client&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;usr_info&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 looks cleaner and async await seems to be more intuitive to use.&lt;/p&gt;

</description>
      <category>node</category>
      <category>beginners</category>
      <category>oauth20</category>
      <category>googleapis</category>
    </item>
    <item>
      <title>What makes this site so quick?</title>
      <dc:creator>Arpan Kc</dc:creator>
      <pubDate>Thu, 19 Oct 2017 17:49:13 +0000</pubDate>
      <link>https://dev.to/nipeshkc7/what-makes-this-site-so-quick-d40</link>
      <guid>https://dev.to/nipeshkc7/what-makes-this-site-so-quick-d40</guid>
      <description>&lt;p&gt;I have been a frequent visitor of this site for more than a week now. And have to say I am amazed at how snappy this is. What is the secret? Could someone explain.&lt;/p&gt;

&lt;p&gt;(I am sorry if this is a stupid question.) &lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
  </channel>
</rss>
