<?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: aadilraza339</title>
    <description>The latest articles on DEV Community by aadilraza339 (@aadilraza339).</description>
    <link>https://dev.to/aadilraza339</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%2F525320%2Fd65373af-d60b-4821-8d05-6e944fe43d71.jpeg</url>
      <title>DEV Community: aadilraza339</title>
      <link>https://dev.to/aadilraza339</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aadilraza339"/>
    <language>en</language>
    <item>
      <title>Shopify CLI app deploy on Heroku</title>
      <dc:creator>aadilraza339</dc:creator>
      <pubDate>Thu, 25 Aug 2022 06:41:00 +0000</pubDate>
      <link>https://dev.to/aadilraza339/shopify-cli-app-deploy-on-heroku-a5o</link>
      <guid>https://dev.to/aadilraza339/shopify-cli-app-deploy-on-heroku-a5o</guid>
      <description>&lt;h1&gt;
  
  
  What is the Shopify CLI app
&lt;/h1&gt;

&lt;p&gt;Shopify CLI is a command-line interface tool that helps you build Shopify apps. It quickly generates Shopify apps and scaffolds app extensions. You can also use it to automate many common development tasks.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Heroku
&lt;/h1&gt;

&lt;p&gt;Heroku is a container-based cloud Platform as a Service (PaaS). Developers use Heroku to deploy, manage, and scale modern apps&lt;/p&gt;

&lt;p&gt;Let's focus to deploy an app on Heroku&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create your account on heroku first&lt;/li&gt;
&lt;li&gt;install heroku CLI &lt;a href="https://devcenter.heroku.com/articles/heroku-cli"&gt;link&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;create an account on Shopify&lt;/li&gt;
&lt;li&gt;create an account on Shopify partners &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;you can follow this &lt;a href="https://shopify.dev/themes/tools/cli/installation"&gt;link&lt;/a&gt; to install Shopify-cli&lt;/p&gt;

&lt;p&gt;once you install Shopify CLI, now you can log in to Shopify.&lt;br&gt;
&lt;code&gt;shopify login&lt;/code&gt;&lt;br&gt;
&lt;code&gt;shopify app create node&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will ask your app's name, simply enter a name related to your app, for now, you can give &lt;code&gt;tutorial-app&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lm-Vs3jO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ht886yf1mvsohnxaml71.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lm-Vs3jO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ht886yf1mvsohnxaml71.png" alt="Image description" width="675" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this tutorial, I use node-js. &lt;/p&gt;

&lt;p&gt;To run the app locally  &lt;code&gt;shopify app serve&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you can make modifications accordingly with your required &lt;br&gt;
if not initially &lt;br&gt;
&lt;code&gt;git init&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git add&lt;/code&gt;&lt;br&gt;
&lt;code&gt;git commit -m "deploy on heroku"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;create an app on Heroku&lt;br&gt;
&lt;code&gt;heroku create&lt;/code&gt;&lt;br&gt;
it will print an app link on your terminal&lt;br&gt;
&lt;code&gt;git push heroku master&lt;/code&gt;&lt;br&gt;
&lt;code&gt;shopify app deploy heroku&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open your app set-up and replace your Heroku live URL with ngrok&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--idJ8vo5a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vou3pxxcf3hhjmcttaan.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--idJ8vo5a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vou3pxxcf3hhjmcttaan.png" alt="Image description" width="880" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can your config variables &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VCgWt984--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cahj9l9pb9wl9ahd8la.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VCgWt984--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cahj9l9pb9wl9ahd8la.png" alt="Image description" width="777" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Host's value will Heroku live link which had printed on terminal&lt;/p&gt;

&lt;p&gt;Now you can visit your Shopify partner and click on your store&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VcyS1TO_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edgz0f8a0hejzkp4oyd0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VcyS1TO_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edgz0f8a0hejzkp4oyd0.png" alt="Image description" width="880" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wow we have successfully deployed our app on heroku   &lt;/p&gt;

&lt;p&gt;Happy coding :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding JWT Authentication with Node.js</title>
      <dc:creator>aadilraza339</dc:creator>
      <pubDate>Sat, 22 May 2021 15:49:06 +0000</pubDate>
      <link>https://dev.to/aadilraza339/understanding-jwt-authentication-with-node-js-ld3</link>
      <guid>https://dev.to/aadilraza339/understanding-jwt-authentication-with-node-js-ld3</guid>
      <description>&lt;p&gt;What is JSON Web Token?&lt;br&gt;
JWT is a stander and secure way to transfer information between parties as a JSON object, that can be verifiable and JWT makes the tokens easy to transfer through an HTTP request.&lt;br&gt;
JWT is mainly used for authentication. After a user signs in to an application, the application then assigns a JWT token to that user. Whenever user will make requests will include the assigned JWT token. This token tells the server what routes, services, and resources the user is allowed to access.&lt;br&gt;
Structure of a JWT&lt;br&gt;
Header — consists of two parts: the type of token (i.e., JWT) and the signing algorithm (i.e., HS512) header.&lt;br&gt;
Payload — Contains the claims that provide information about a user who has been authenticated along with other information such as token expiration time payload&lt;br&gt;
Signature — Final part of a token that wraps in the encoded header and payload, along with the algorithm and a secret.&lt;br&gt;
Implement JWT with Node JS&lt;br&gt;
Before you go ahead with this tutorial, you should have knowledge of express framework Here's the Link&lt;br&gt;
for reference.&lt;br&gt;
Create a file called index.js in the project directory. This is the only file that we create and work on in this project in order to keep things simple. Our main goal is to understand how JWTs work in a Node.js application.&lt;br&gt;
So, let’s go ahead and understand what each snippet of code does in this file.&lt;br&gt;
We are importing a couple of modules that we will be needing in the application: express, and JWT. We can install both modules with this command npm i express jsonwebtoken --save from the command line. Then in the index.js file paste the below code 👇.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
const jwt = require("jsonwebtoken");
const app = express();
app.use(express.json())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are going to write a post method with the express, which will help us to create a token.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post("/api/login", (req, res, next) =&amp;gt; {
  const user = {
    id: 1,
    username: "john",
    email: "john@gmail.com"
  };
  const password = '*******'
  if(user.username === req.body.username &amp;amp;&amp;amp; password === req.body.password) {
    jwt.sign({ user: user }, "secretkey", (err, token) =&amp;gt; {
      res.cookie('token',token);
      res.status(200).json(
          "Auth successful"
        );
    });
  }
  else {
    res.status(401).json('Unauthorized client')
  }
});
// server running
app.listen(process.env.PORT || 3000, () =&amp;gt; {
    console.log("Server started with express..");
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;! Don’t forget to run the index.js file use this command node index.js&lt;br&gt;
Explanation&lt;br&gt;
sign() method to create a JSON Web Token for that user and returns the token in the form of a JSON string. Now you can make a request through the postman on this URL &lt;a href="http://localhost:8000/api/login"&gt;http://localhost:8000/api/login&lt;/a&gt; and the token will save in the cookies&lt;br&gt;
To make sure you got token, you can check in the postman, open postman, and in the top-right side you can click cookies, and then you should get token 👇&lt;/p&gt;

&lt;p&gt;you can expand it by click on the token&lt;/p&gt;

&lt;p&gt;Finally, we define another post method with verifyToken() that takes care of the token verification process. Let’s see How we can implement&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post("/api/post/verify", (req, res) =&amp;gt; {
  let token = req.headers.cookie.split("=")[1]
  jwt.verify(token, "secretkey", (err, authData) =&amp;gt; {
    if (err) {
      res.sendStatus(403);
    } else {
      res.json({
        message: "verify successfully.",
        authData
      });
    }
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="http://localhost:8000/api/post/verify"&gt;http://localhost:8000/api/post/verify&lt;/a&gt; make a request on it&lt;br&gt;
Explanation&lt;br&gt;
We took the token from our &lt;code&gt;req.cookies.split("=")[1]&lt;/code&gt; &lt;strong&gt;or&lt;/strong&gt; simplest way to get token use this &lt;a href="https://www.npmjs.com/package/cookie-parser"&gt;NPM cookie-parser&lt;/a&gt; and then store it in token variable and by the use of .verify() method we are verifying token which we assigned in the previous request&lt;br&gt;
and if the token is valid, will get a message verify successfully on the postman or 403.&lt;br&gt;
HAPPY CODE LIFE&lt;br&gt;
Aadil Raza&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is .env file in node JS</title>
      <dc:creator>aadilraza339</dc:creator>
      <pubDate>Sat, 22 May 2021 11:38:53 +0000</pubDate>
      <link>https://dev.to/aadilraza339/what-is-env-file-in-node-js-3h6c</link>
      <guid>https://dev.to/aadilraza339/what-is-env-file-in-node-js-3h6c</guid>
      <description>&lt;p&gt;Its environment variables file. In simple term, it is a variable text file. In this file we set a variable with value and that you wouldn’t want to share with anyone, purpose of file is keep as secret and secure because in .env file we store our database password, username, API key etc…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;how you can set variable &lt;br&gt;
create a file called .env&lt;br&gt;
open it in any editer &lt;br&gt;
Then &lt;br&gt;
You can easily set your environment variables and values with the syntax ENV_VARIABLE=VALUE and boom! 🙂&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcoder-202%2Fimage%2Fupload%2Fv1621670720%2Fvenu18%2FScreenshot_2021-05-22_at_1.34.56_PM_p4qr3y.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%2Fres.cloudinary.com%2Fcoder-202%2Fimage%2Fupload%2Fv1621670720%2Fvenu18%2FScreenshot_2021-05-22_at_1.34.56_PM_p4qr3y.png" alt=".env"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This how you can use these variables in your Node JS porject. &lt;br&gt;
Run it on your command line &lt;code&gt;npm i dotenv --save&lt;/code&gt;&lt;br&gt;
&lt;code&gt;require('dotenv').config()&lt;/code&gt; Is required in the file where you want to use.&lt;br&gt;
To see if you have connected with your .env simply console &lt;code&gt;console.log(process.env);&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fcoder-202%2Fimage%2Fupload%2Fv1621671052%2Fvenu18%2FScreenshot_2021-05-22_at_1.40.33_PM_dhbxef.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%2Fres.cloudinary.com%2Fcoder-202%2Fimage%2Fupload%2Fv1621671052%2Fvenu18%2FScreenshot_2021-05-22_at_1.40.33_PM_dhbxef.png" alt="OUTPUT"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;See some more example 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;require('dotenv').config()
const db = require('db')
db.connect({
  host: process.env.DB_HOST,
  username: process.env.DB_USER,
  password: process.env.DB_PASS
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;!NOTE&lt;br&gt;
.env includes sensitive information, so it should not be pushed with your code/GIT repo. Please make sure!&lt;br&gt;
This is how you can avoid .env to push in your repo using GIT.&lt;/p&gt;

&lt;p&gt;Create a file called &lt;code&gt;.gitignore&lt;/code&gt; in the root directory of your project, then open it, then write &lt;code&gt;.env&lt;/code&gt; in it. Now git will avoid pushing your .env file, you can know more about how .gitignore works &lt;a href="https://www.atlassian.com/git/tutorials/saving-changes/gitignore" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HAPPY CODE LIFE&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
