<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ qr code - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ qr code - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 24 Jun 2026 10:06:24 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/qr-code/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Build a QR Code Generator for URLs with Node.js, Next.js, and Azure Blob Storage ]]>
                </title>
                <description>
                    <![CDATA[ A while ago, a client asked me to help them create a special app for generating QR codes so users could receive payments. What set this app apart was that instead of users entering a URL to generate a QR code, they would initiate a request through th... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-a-qr-code-generator-using-nodejs-nextjs-azure-blob-storage/</link>
                <guid isPermaLink="false">66d45dd5a3a4f04fb2dd2e2d</guid>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ node js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ qr code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ayomide Wilfred Adeyemi ]]>
                </dc:creator>
                <pubDate>Fri, 10 May 2024 15:41:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/05/qr-code-image-real.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A while ago, a client asked me to help them create a special app for generating QR codes so users could receive payments.</p>
<p>What set this app apart was that instead of users entering a URL to generate a QR code, they would initiate a request through the app. Then a unique QR code would be generated which would be associated with their account details. The QR code would then be displayed on their screen while the payer scans the QR code using their mobile device's camera.</p>
<p>In this tutorial, you'll learn how to develop a custom QR code generator for URLs using Node.js and Next.js. I'll walk you through the process step by step, including setting up Azure Blob Storage to store the generated URLs. These URLs will then be displayed in the form of QR codes in your Next.js frontend application.</p>
<p>We'll build the backend of the application using <code>Node.js</code> and the <code>Express</code> framework, and the frontend (which interacts with the backend) with <code>Next.js</code>.</p>
<p>I'll also provide explanations on QR codes, the concept of <code>buffers</code> for handling binary data in Node.js, and how it is being used to stream the QR code image data to Azure Blob Storage.</p>
<p>So, let dive in.</p>
<h3 id="heading-prerequisites"><strong>Prerequisites</strong></h3>
<p>Before you begin you'll need an active <a target="_blank" href="https://azure.microsoft.com/en-us/get-started/azure-portal">Azure</a> account and subscription to create an Azure blob storage.</p>
<h2 id="heading-table-of-contents"><strong>Table of Contents</strong></h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-what-is-a-qr-code">What is a QR Code</a>?</p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-set-up-azure-blob-storage">How to Set Up Azure Blob Storage</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-nodejs-qr-code">Node.js QR Code</a></p>
</li>
<li><p><a class="post-section-overview" href="#code-overwiew">Code Overview</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-connect-the-frontend-application">How to Connect the Frontend Application</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-nextjs-code-walkthrough">Next.js Code Walkthrough</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-start-the-application-locally">How to Start the Application Locally</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ol>
<h2 id="heading-what-is-a-qr-code">What is a QR Code?</h2>
<p>According to <a target="_blank" href="https://www.investopedia.com/terms/q/quick-response-qr-code.asp">Investopedia</a>, a Quick Response (QR) code functions as a specialized barcode, scannable by digital devices, that stores data within a grid of square pixels.</p>
<p>QR codes are extensively employed in digital payments, cryptocurrency, and transmitting web addresses to mobile devices. They can encode URLs, facilitating webpage access.</p>
<p>Now, let's delve into the process of programmatically generating QR codes. Today, I'll demonstrate this step-by-step. To begin, you'll set up an <code>Azure Blob Storage</code> instance in your <code>Azure Portal</code>.</p>
<h2 id="heading-how-to-set-up-azure-blob-storage">How to Set Up Azure Blob Storage</h2>
<p><a target="_blank" href="https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blobs-overview">Azure Blob Storage</a> is a cloud-based storage service provided by Microsoft Azure. It is part of the Azure Storage suite, which also includes services such as Azure Files, Azure Queues, and Azure Tables.</p>
<p>Azure Blob Storage is designed to store large amounts of unstructured data, such as text or binary data, in the form of objects called blobs. If you are familiar with AWS, Azure Blob Storage is similar to an S3 bucket. Storage accounts are primarily accessed via REST API.</p>
<h3 id="heading-step-1-create-a-storage-account">Step 1: Create a storage account</h3>
<p>You can create your storage account by simply searching for Storage account in the search bar at the top of the Azure Portal.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-16.08.23.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Create Storage Accounts in Azure Portal</em></p>
<p>You can then run through the steps to create your storage account. Just note that this name needs to be unique and it also needs to be all lower case – no spaces but it can include numbers.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-16.16.46.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Create a New Resource Group</em></p>
<h3 id="heading-step-2-create-a-container">Step 2: Create a container</h3>
<p>After creating your storage account, you can now create a <code>container</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-16.44.16.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Create a New Container</em></p>
<p>When accessing blob storage with the <code>QR codes</code> stored in Azure Storage, the URL typically follows a structure like <code>https://&lt;storage_account_name&gt;.blob.core.windows.net/&lt;container_name&gt;/&lt;blob_name&gt;</code>.</p>
<p>Having a container allows us to structure the URLs in a meaningful and organized way, making it easier to manage and share the generated QR codes.</p>
<h3 id="heading-step-3-obtain-azure-storage-connection-string">Step 3: Obtain Azure Storage connection string</h3>
<p>In the <code>Security + networking</code> section, select "Access keys."</p>
<p>Make sure to copy the connection string and save it somewhere as it's required to establish a secure connection between the Azure Storage account and the <code>Node.js</code> application.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-16.54.39.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Obtain Access Key for the Container</em></p>
<p>That concludes the discussion on Microsoft Azure Storage. I must say, I thoroughly enjoyed exploring and solving these challenges.</p>
<p>Next, you will be diving into coding, specifically around <code>Nodejs</code> and and then moving on to frontend development, where you'll be using <code>Next.js</code>.</p>
<h2 id="heading-nodejs-qr-code">Node.js QR Code</h2>
<p>First, you need to install <code>Node.js</code> and <code>npm</code> on your computer. Go to the <a target="_blank" href="https://nodejs.org/">Node.js</a> website and download the version for your computer if you don't have it already.</p>
<p>Once you've installed them, check if Node.js and npm are installed correctly by typing these commands in your terminal:</p>
<pre><code class="lang-bash">node -v
npm -v
</code></pre>
<p>Next, go to this GitHub <a target="_blank" href="https://github.com/ayowilfred95/azure-qr-code-generator.git">link</a> to fork the project and then clone it to your preferred directory on your computer.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-17.26.39--2-.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Github Repository Project</em></p>
<p>Once you've cloned the project repository, open the project with your code editor. I'm using <a target="_blank" href="https://code.visualstudio.com/download">VS Code</a>. You'll notice that the project has of two folders: <code>server</code> and <code>frontend</code>. You'll start by navigating to the <code>server</code> folder by typing <code>cd server</code> in your terminal and then press <code>Enter</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-17.48.03.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Change the current directory to a directory named "server."</em></p>
<p>Now you can install all the necessary dependencies by running <code>npm install</code>. This command will download and install all the required packages for the server-side application.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-17.55.01.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>installation of dependencies</em></p>
<p>If everything went well, you should see something like this below after <code>npm install</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-17.51.59.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Successful Installation</em></p>
<p>Next, you need to create a <code>.env</code> file in the <code>server</code> directory to store your environment variables. It's not advisable to hardcode sensitive credentials. You can do this easily by running <code>touch .env</code> in your terminal.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-17.59.38.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Create a new file named ".env"</em></p>
<p>In the newly created <code>.env</code> file, you'll define three variables that your application depends on: <code>CONTAINER_NAME</code> , <code>AZURE_STORAGE_CONNECTION_STRING</code>, and <code>PORT</code> .</p>
<p>Assign 'qrcode' as the value for <code>CONTAINER_NAME</code>. This was the name of the container you created inside the Azure Storage account. Also, set the <code>PORT</code> to <code>8000</code>, which is the port your backend application will be listening on.</p>
<p>Now, for the <code>AZURE_STORAGE_CONNECTION_STRING</code>, you'll need to obtain the secret key from the access key you obtained earlier. Copy the connection string and paste it as the value for <code>AZURE_STORAGE_CONNECTION_STRING</code> in the <code>.env</code> file.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-18.18.00.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Store Secret Variables</em></p>
<p>Once you've added these environment variables to the <code>.env</code> file, save it and you're all set to run the server-side of the application!</p>
<p>Before you run the application, let me quickly explain the code. Click on the <code>index.js</code> file.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-18.18.28.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>View Index.js file</em></p>
<h3 id="heading-code-overview">Code overview:</h3>
<p>Below is the code snippet containing the necessary logic for generating QR codes and establishing a connection with the Azure storage account you previously created.</p>
<pre><code class="lang-bash">const express = require(<span class="hljs-string">'express'</span>);
const { BlobServiceClient, generateBlobSASQueryParameters, BlobSASPermissions } = require(<span class="hljs-string">'@azure/storage-blob'</span>);
const qrcode = require(<span class="hljs-string">'qrcode'</span>);
const { v4: uuidv4 } = require(<span class="hljs-string">'uuid'</span>);
const { Readable } = require(<span class="hljs-string">'stream'</span>);
const dotenv = require(<span class="hljs-string">'dotenv'</span>);

dotenv.config();

const app = express();
const port = process.env.PORT || 5000;

// Allowing CORS <span class="hljs-keyword">for</span> <span class="hljs-built_in">local</span> testing
const origins = [
    <span class="hljs-string">"http://localhost:3000"</span>
];

app.use((req, res, next) =&gt; {
    res.header(<span class="hljs-string">'Access-Control-Allow-Origin'</span>, origins.join(<span class="hljs-string">','</span>));
    res.header(<span class="hljs-string">'Access-Control-Allow-Headers'</span>, <span class="hljs-string">'Origin, X-Requested-With, Content-Type, Accept'</span>);
    next();
});


const containerName = process.env.CONTAINER_NAME;

const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.AZURE_STORAGE_CONNECTION_STRING);

app.use(express.json());

app.post(<span class="hljs-string">'/generate-qr'</span>, async (req, res) =&gt; {
    const { url } = req.body;

    // Generate QR Code
    console.log(<span class="hljs-string">'Received URL:'</span>, url);
    const qrCode = await qrcode.toBuffer(url);

    const bufferStream = new Readable();
    bufferStream.push(qrCode);
    bufferStream.push(null);

    // Generate unique file name <span class="hljs-keyword">for</span> Azure Blob Storage
    const fileName = `qr_codes/<span class="hljs-variable">${uuidv4()}</span>.png`;

    try {
        const containerClient = blobServiceClient.getContainerClient(containerName);
        const blockBlobClient = containerClient.getBlockBlobClient(fileName);

        await blockBlobClient.uploadStream(bufferStream, 4 * 1024 * 1024, 20, {
            blobHTTPHeaders: {
                blobContentType: <span class="hljs-string">'image/png'</span>
            }
        });

        // Generate SAS token <span class="hljs-keyword">for</span> blob
        const sasToken = generateSasToken(blockBlobClient);

        // Generate the Blob URL with SAS token
        const blobUrlWithSasToken = `<span class="hljs-variable">${blockBlobClient.url}</span>?<span class="hljs-variable">${sasToken}</span>`;

        // Send response with the Blob URL containing SAS token
        res.json({ qr_code_url: blobUrlWithSasToken });
    } catch (error) {
        console.error(<span class="hljs-string">'Error generating QR Code:'</span>, error);
        res.status(500).json({ error: <span class="hljs-string">'Internal Server Error'</span> });
    }
});

// Function to generate SAS token <span class="hljs-keyword">for</span> blob
<span class="hljs-keyword">function</span> generateSasToken(blobClient) {
    const blobSAS = generateBlobSASQueryParameters({
        containerName: blobClient.containerName,
        blobName: blobClient.blobName,
        permissions: BlobSASPermissions.parse(<span class="hljs-string">"r"</span>), // Read permission
        startsOn: new Date(),
        expiresOn: new Date(new Date().valueOf() + 86400) // Token expires <span class="hljs-keyword">in</span> 24 hours
    }, blobClient.credential);

    <span class="hljs-built_in">return</span> blobSAS.toString();
}

app.listen(port, () =&gt; {
    console.log(`Server is running on port <span class="hljs-variable">${port}</span>`);
});
</code></pre>
<p>Now I'll give a detailed explanation of the code structure, functionalities, and key components of the application.</p>
<h4 id="heading-importing-required-modules">Importing required modules:</h4>
<ul>
<li><p><code>const express = require('express')</code>: This line imports the Express.js framework, which is a Node.js web application framework for building web applications and APIs. It allows you to define routes, handle HTTP requests, and more.</p>
</li>
<li><p><code>const { BlobServiceClient, generateBlobSASQueryParameters, BlobSASPermissions } = require('@azure/storage-blob')</code>: This line imports specific modules from the <code>@azure/storage-blob</code> package, which is the Azure Blob Storage SDK for JavaScript. It allows you to interact with Azure Blob Storage from our Node.js application.</p>
</li>
<li><p><code>const qrcode = require('qrcode')</code>: This line imports the <code>qrcode</code> module, which is a popular Node.js library for generating QR codes.</p>
</li>
<li><p><code>const{ v4: uuidv4 } = require('uuid')</code>: This line imports the <code>uuid</code> module and specifically extracts the <code>v4</code> function as <code>uuidv4</code>. The <code>uuid</code> module is used to generate universally unique identifiers (UUIDs) in Node.js.</p>
</li>
<li><p><code>const{ Readable } = require('stream')</code>: This line imports the <code>Readable</code> class from the built-in Node.js <code>stream</code> module. The <code>Readable</code> class is used to create readable streams, which are useful for handling data that can be read sequentially.</p>
</li>
</ul>
<h4 id="heading-configuring-environment-variables">Configuring environment variables:</h4>
<ul>
<li><code>dotenv.config();</code>: This line loads environment variables from a <code>.env</code> file into <code>process.env</code>. The <code>.env</code> file typically contains <code>CONTAINER_NAME</code> and <code>AZURE_STORAGE_CONNECTION_STRING</code> you specify in your <code>.env</code> file.</li>
</ul>
<h4 id="heading-initializing-the-express-application">Initializing the Express application:</h4>
<ul>
<li><code>const app = express();</code>: This line initializes an Express application instance, which you'll use to define routes, middleware, and other configurations for your web application.</li>
</ul>
<h4 id="heading-defining-port-configuration">Defining port configuration:</h4>
<ul>
<li><code>const port = process.env.PORT || 5000</code>: This line sets the port number for the Express application. It retrieves the port number from the <code>process.env.PORT</code> environment variable, if it exists. If not, it defaults to port <code>5000</code>. This allows flexibility for deploying the application in different environments where the port may be specified externally.</li>
</ul>
<h4 id="heading-allowing-cors-for-local-testing">Allowing CORS for local testing:</h4>
<ul>
<li><p>CORS (Cross-Origin Resource Sharing) is a security feature implemented by web browsers to restrict resources from being requested from another domain or application.</p>
</li>
<li><p>In this section, CORS is being configured to allow requests from a specific origin (<code>http://localhost:3000</code>), which is typically used during local development.</p>
</li>
<li><p>The <code>app.use()</code> function is used to add middleware to the Express application. Here, a middleware function is defined that sets the necessary CORS headers on every HTTP response.</p>
</li>
<li><p><code>res.header('Access-Control-Allow-Origin', origins.join(','))</code>: Sets the value of the <code>Access-Control-Allow-Origin</code> header to allow requests from the specified origins (in this case, <code>http://localhost:3000</code>).</p>
</li>
<li><p><code>res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')</code>: Sets the allowed headers for the CORS request.</p>
</li>
<li><p><code>next()</code>: Calls the next middleware function in the stack.</p>
</li>
</ul>
<h4 id="heading-azure-blob-storage-configuration">Azure Blob Storage configuration:</h4>
<ul>
<li><p><code>containerName</code> and <code>blobServiceClient</code> are initialized using environment variables (<code>process.env.CONTAINER_NAME</code> and <code>process.env.AZURE_STORAGE_CONNECTION_STRING</code>) configured earlier.</p>
</li>
<li><p><code>blobServiceClient</code> is initialized using the <code>fromConnectionString()</code> method from the <code>BlobServiceClient</code> class provided by the <code>@azure/storage-blob</code> package. This allows the application to interact with Azure Blob Storage using the provided connection string.</p>
</li>
</ul>
<h4 id="heading-express-application-configuration">Express application configuration:</h4>
<ul>
<li><code>app.use(express.json())</code>: Adds middleware to parse JSON bodies of incoming requests. This enables the application to handle JSON data in requests.</li>
</ul>
<h4 id="heading-endpoint-for-generating-qr-codes">Endpoint for generating QR codes:</h4>
<ul>
<li><p>Defines a POST endpoint at <code>/generate-qr</code> to handle requests for generating QR codes.</p>
</li>
<li><p>Upon receiving a request, the endpoint extracts the URL from the request body and generates a QR code image using the <code>qrcode.toBuffer()</code> function.</p>
</li>
<li><p>The generated QR code image is then uploaded to Azure Blob Storage as a blob with a unique file name.</p>
</li>
<li><p>After successfully uploading the image, a Shared Access Signature (SAS) token is generated for the blob, which provides temporary access to the blob with specified permissions (in this case, read-only).</p>
</li>
<li><p>Finally, the endpoint responds with a JSON object containing the URL of the generated QR code image along with the SAS token.</p>
</li>
</ul>
<h4 id="heading-function-to-generate-sas-token-for-blob">Function to generate SAS token for blob:</h4>
<ul>
<li>Defines a function <code>generateSasToken()</code> to generate a SAS token for a given blob client (block blob client in this case). The SAS token is generated with read permissions and an expiration time set to 24 hours.</li>
</ul>
<h4 id="heading-listening-on-port">Listening on port:</h4>
<ul>
<li>The Express application listens on the configured port (<code>port</code>) for incoming HTTP requests. When the server starts, it prints a message indicating the port it is listening on.</li>
</ul>
<p>Now, you can start the application locally.</p>
<p>To start the application, simply run <code>npm start</code> as shown below. If all goes well, you'll observe the message <code>Server is running on port 8000</code> printed on your console.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-18.36.50.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Start the Application locally</em></p>
<h2 id="heading-how-to-connect-the-frontend-application">How to Connect the Frontend Application</h2>
<p>Now it is time to connect the frontend application with the backend application that is listening on Port 8000.</p>
<p>A typical full-stack application usually consists of at least two main components: a frontend (client-side) and a backend (server-side).</p>
<p><strong>Frontend Component</strong>: This is the part of the application that users interact with directly. It's typically built using technologies like HTML, CSS, and JavaScript frameworks like React, Angular, or Next.js.</p>
<p><strong>Backend Component</strong>: This is the part of the application that handles data storage, retrieval, and server side connectivity. It's usually built using server-side programming languages like Node.js (with frameworks like Express.js or Nest.js), Python (with frameworks like Django or Flask), Java (with frameworks like Spring), or Ruby (with frameworks like Ruby on Rails).</p>
<p>The backend communicates with the frontend, processes requests from users, interacts with databases, and generates responses.</p>
<p>To navigate to the frontend folder, open a new terminal by clicking the <code>+</code> , then use <code>cd frontend</code> to enter the frontend folder.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-18.57.14.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Navigate to Frontend Directory</em></p>
<p>Now, you can install all the necessary dependencies by running <code>npm install</code>. This command will download and install all the required packages for the Nextjs client-side application.</p>
<p>If everything went well, you should see something like this after <code>npm install</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-17.51.59-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Successful Installation of Dependencies</em></p>
<p>Before you run the application, let me quickly explain the code.Navigate to the frontend folder, then inside the <code>src/app</code> directory, click on the page.js file.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-18.50.17.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>View page.js file</em></p>
<h3 id="heading-nextjs-code-walkthrough">Next.js Code Walkthrough</h3>
<p>This code represents a React component serving as the frontend for the QR code generator backend application you've recently built. This component allows users to input a URL, submit it, and receive the corresponding QR code image for display.</p>
<pre><code class="lang-bash"><span class="hljs-string">'use client'</span>

import { useState } from <span class="hljs-string">'react'</span>;
import axios from <span class="hljs-string">'axios'</span>;

<span class="hljs-built_in">export</span> default <span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">Home</span></span>() {
  const [url, setUrl] = useState(<span class="hljs-string">''</span>);
  const [qrCodeUrl, setQrCodeUrl] = useState(<span class="hljs-string">''</span>);

  const handleSubmit = async (e) =&gt; {
    e.preventDefault();
    try {
      const response = await axios.post(<span class="hljs-string">'http://localhost:8000/generate-qr'</span>, { url });
      setQrCodeUrl(response.data.qr_code_url);
    } catch (error) {
      console.error(<span class="hljs-string">'Error generating QR Code:'</span>, error);
    }
  };

  <span class="hljs-built_in">return</span> (
    &lt;div style={styles.container}&gt;
      &lt;h1 style={styles.title}&gt;QR Code Generator&lt;/h1&gt;
      &lt;form onSubmit={handleSubmit} style={styles.form}&gt;
        &lt;input
          <span class="hljs-built_in">type</span>=<span class="hljs-string">"text"</span>
          value={url}
          onChange={(e) =&gt; setUrl(e.target.value)}
          placeholder=<span class="hljs-string">"Enter URL like https://www.google.com"</span>
          style={styles.input}
        /&gt;
        &lt;button <span class="hljs-built_in">type</span>=<span class="hljs-string">"submit"</span> style={styles.button}&gt;Generate QR Code&lt;/button&gt;
      &lt;/form&gt;
      {qrCodeUrl &amp;&amp; &lt;img src={qrCodeUrl} alt=<span class="hljs-string">"QR Code"</span> style={styles.qrCode} width=<span class="hljs-string">"200"</span> height=<span class="hljs-string">"200"</span> /&gt;}
    &lt;/div&gt;
  );
}

// Styles
const styles = {
  container: {
    minHeight: <span class="hljs-string">'100vh'</span>,
    display: <span class="hljs-string">'flex'</span>,
    flexDirection: <span class="hljs-string">'column'</span>,
    alignItems: <span class="hljs-string">'center'</span>,
    justifyContent: <span class="hljs-string">'center'</span>,
    backgroundColor: <span class="hljs-string">'#121212'</span>,
    color: <span class="hljs-string">'white'</span>,
  },
  title: {
    margin: <span class="hljs-string">'0'</span>,
    lineHeight: <span class="hljs-string">'1.15'</span>,
    fontSize: <span class="hljs-string">'4rem'</span>,
    textAlign: <span class="hljs-string">'center'</span>,
  },
  form: {
    display: <span class="hljs-string">'flex'</span>,
    flexDirection: <span class="hljs-string">'column'</span>,
    alignItems: <span class="hljs-string">'center'</span>,
  },
  input: {
    padding: <span class="hljs-string">'10px'</span>,
    borderRadius: <span class="hljs-string">'5px'</span>,
    border: <span class="hljs-string">'none'</span>,
    marginTop: <span class="hljs-string">'20px'</span>,
    width: <span class="hljs-string">'300px'</span>,
    color: <span class="hljs-string">'#121212'</span>

  },
  button: {
    padding: <span class="hljs-string">'10px 20px'</span>,
    marginTop: <span class="hljs-string">'20px'</span>,
    border: <span class="hljs-string">'none'</span>,
    borderRadius: <span class="hljs-string">'5px'</span>,
    backgroundColor: <span class="hljs-string">'#0070f3'</span>,
    color: <span class="hljs-string">'white'</span>,
    cursor: <span class="hljs-string">'pointer'</span>,
  },
  qrCode: {
    marginTop: <span class="hljs-string">'20px'</span>,
  },
};
</code></pre>
<p>Now I'll give a detailed explanation of the frontend application's code structure, functionalities, and key components.</p>
<h4 id="heading-state-management">State management:</h4>
<ul>
<li><p><code>import { useState } from 'react'</code> imports the <code>useState</code> hook from React to manage state within the component.</p>
</li>
<li><p><code>const [url, setUrl] = useState('')</code> and <code>const [qrCodeUrl, setQrCodeUrl] = useState('')</code>: This state variables, <code>url</code> and <code>qrCodeUrl</code>, are initialized using the <code>useState</code> hook. These variables hold the input URL and the generated QR code URL, respectively.</p>
</li>
</ul>
<h4 id="heading-form-submission">Form submission:</h4>
<ul>
<li><p>When the form is submitted, the <code>handleSubmit</code> function is triggered.</p>
</li>
<li><p>This function prevents the default form submission behavior by using <code>e.preventDefault()</code>.</p>
</li>
<li><p>It sends a POST request to the server (<code>http://localhost:8000/generate-qr</code>) with the input URL using the <a target="_blank" href="https://axios-http.com/docs/intro">Axios</a> library.</p>
</li>
<li><p>Upon successful response, the generated QR code URL is stored in the <code>qrCodeUrl</code> state variable.</p>
</li>
</ul>
<h4 id="heading-rendering">Rendering:</h4>
<ul>
<li><p>The component renders a title, a form with an input field for entering the URL, and a button to generate the QR code.</p>
</li>
<li><p>When the QR code URL is available (<code>qrCodeUrl</code> is not empty), an image element is rendered to display the generated QR code.</p>
</li>
</ul>
<h4 id="heading-styling">Styling:</h4>
<ul>
<li><p>The component includes inline styles defined using JavaScript objects.</p>
</li>
<li><p>Styles are applied to the container, title, form, input field, button, and QR code image.</p>
</li>
</ul>
<h2 id="heading-how-to-start-the-application-locally">How to Start the Application Locally</h2>
<p>Now, you can start the application locally.</p>
<p>To start the application, simply run <code>npm run dev</code> as shown below. If all goes well, you'll observe the message <a target="_blank" href="http://localhost:3000"><code>http://localhost:3000</code></a> printed in your console.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-08-at-15.18.18.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Application ready to start</em></p>
<p>Open your browser and paste the URL <a target="_blank" href="http://localhost:3000"><code>http://localhost:3000</code></a>. The browser should render the application and look exactly as shown below.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-09-at-11.32.04.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Application running in Browser</em></p>
<p>Paste in the URL of a website – either your portfolio website or any website you wish to generate a QR code for. I pasted my portfolio website URL, <a target="_blank" href="https://wilfred-portfolio.vercel.app/"><code>https://wilfred-portfolio.vercel.app/</code></a>, into the URL box. See the result below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/05/Screenshot-2024-05-07-at-20.32.40.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>QR Code generated successfully</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>When it comes to picking the right tools, technology choices are important. Next.js is great for making the front end of a website, while Node.js works well for handling server-side tasks. Also Azure blob storage is great for storing unstructured data such as binary data like QR code.</p>
<p>But remember, this journey is not just about writing code. It's also about learning about different technologies and picking the best ones for what you need to do.</p>
<p>As I finish up this tutorial, I'd like to keep asking for feedback to ensure that this tutorial stays helpful. Feel free to share your thoughts or comments with me.</p>
<p>Thanks for reading!</p>
<p>Happy coding! 🚀</p>
<h3 id="heading-contact-me"><strong>Contact Me:</strong></h3>
<ul>
<li><p><a target="_blank" href="https://twitter.com/ayomidewilfred9">Twitter</a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/ayomide-wilfred-95083a104/">LinkedIn</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/Ayowilfred95">GitHub</a></p>
</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create Stunning QR Codes with Python ]]>
                </title>
                <description>
                    <![CDATA[ By Shittu Olumide A quick response (QR) code is a barcode that a digital device can easily scan. It encodes data as a series of pixels in a square grid.  Tracking information about supply chains using QR codes is very useful in marketing and advertis... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-stunning-qr-codes-with-python/</link>
                <guid isPermaLink="false">66d460ffd14641365a050969</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ qr code ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 21 Dec 2022 15:40:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/12/How-to-create-stunning-QR-codes-with-python-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Shittu Olumide</p>
<p>A quick response (QR) code is a barcode that a digital device can easily scan. It encodes data as a series of pixels in a square grid. </p>
<p>Tracking information about supply chains using QR codes is very useful in marketing and advertising campaigns.</p>
<p>The International Organization for Standardization certified QR codes as a global standard in 2000. They are an improvement over the previous uni-dimensional barcodes (ISO).</p>
<p>QR codes were developed in the 1990s to provide more information than a regular barcode. They were created by Denso Wave, a Toyota affiliate, to monitor the production of vehicles. </p>
<p>In contrast to barcodes, which need a beam of light to bounce off the parallel lines, QR codes may be scanned digitally by devices like smartphones.</p>
<p>QR codes are used in cryptocurrency systems to enable digital payments, such as when displaying a Bitcoin address. QR codes are also often used to communicate site URLs to mobile devices. </p>
<p>In this article, we will use the <code>segno</code> library to create beautiful QR codes that perform so many functions. </p>
<h2 id="heading-what-is-segno">What is Segno?</h2>
<p><a target="_blank" href="https://pypi.org/project/segno/0.1.5/#:~:text=Segno%20%E2%80%93%20Python%20QR%20Code%20and,Codes%20with%20nearly%20no%20effort.">Segno</a> is an open-source QR code generator that lets you create both regular and micro QR codes with very little effort. It also doesn't have any dependencies. </p>
<p>Segno offers a few serialization types like SVG, EPS, PNG, PDF, and text output. None of these serializers calls on an external library. Through a plugin design, Segno offers other serialization types. PyPy and Python versions 2.6 to 3.4 were used for testing.</p>
<h3 id="heading-how-to-install-segno">How to Install Segno</h3>
<p>Just like every other Python library, you can install Segno via pip.</p>
<pre><code class="lang-py">pip install segno
</code></pre>
<h2 id="heading-how-to-create-a-qr-code">How to Create a QR Code</h2>
<p>So, using the <code>.make()</code> method, let's start by making the most basic QR code possible. Since the content is so brief, Segno automatically generates a fun-sized "micro QR" code, which carries raw data and that you can copy or transfer.</p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno

price_tag = segno.make(<span class="hljs-string">"Hello World"</span>)
price_tag.save(<span class="hljs-string">"hello-world.png"</span>)
</code></pre>
<p>The QR code is generated and saved into our project directory.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Price-Tag.png" alt="Image" width="600" height="400" loading="lazy">
<em>hello-world.png</em></p>
<p>We can add a border to the QR code to make it look more attractive. You can do this by adding the <code>border</code> parameter to the <code>.save()</code> method.</p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno
qrcode = segno.make(<span class="hljs-string">'Vampire Blues'</span>)
qrcode.save(<span class="hljs-string">'vampire-blues.png'</span>, border=<span class="hljs-number">5</span>)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/vampire-blues.png" alt="Image" width="600" height="400" loading="lazy">
<em>output: vapire-blues.png</em></p>
<p>The QR codes that we have been creating have been very small. We can make them look bigger by adding the scale parameter like this:</p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno
qrcode = segno.make_qr(<span class="hljs-string">'Welcome'</span>)
qrcode.save(<span class="hljs-string">'welcome.png'</span>, scale=<span class="hljs-number">10</span>)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/welcome.png" alt="Image" width="600" height="400" loading="lazy">
<em>welcome.png</em></p>
<h3 id="heading-how-to-create-colorful-qr-codes">How to Create Colorful QR Codes</h3>
<p>We can also create some colorful QR codes with Segno – they are really beautiful. This is possible with the help of many serializers which accept the parameters dark and light to specify the color of the dark modules and light modules.</p>
<p>Here are a couple examples to give you an idea of what's possible:</p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno
qrcode = segno.make(<span class="hljs-string">"Green ave, Kingston"</span>)
qrcode.save(<span class="hljs-string">'address.png'</span>, dark=<span class="hljs-string">'darkred'</span>, light=<span class="hljs-string">'lightblue'</span>, scale=<span class="hljs-number">10</span>)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/address.png" alt="Image" width="600" height="400" loading="lazy">
<em>address.png</em></p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno
qrcode = segno.make(<span class="hljs-string">"Green ave, Kingston"</span>)
<span class="hljs-comment"># Dark modules with alpha transparency</span>
qrcode.save(<span class="hljs-string">'address2.png'</span>, dark=<span class="hljs-string">'#0000ffcc'</span>, scale=<span class="hljs-number">10</span>)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/address2.png" alt="Image" width="600" height="400" loading="lazy">
<em>address2.png</em></p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno
micro_qrcode = segno.make(<span class="hljs-string">'Rain'</span>, error=<span class="hljs-string">'q'</span>)
micro_qrcode.save(<span class="hljs-string">'rain.png'</span>, dark=<span class="hljs-string">'darkblue'</span>, data_dark=<span class="hljs-string">'steelblue'</span>, scale=<span class="hljs-number">5</span>)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/rain.png" alt="Image" width="600" height="400" loading="lazy">
<em>rain.png</em></p>
<h2 id="heading-how-to-save-qr-codes-in-different-formats">How to Save QR Codes in Different Formats</h2>
<p>Segno give us the flexibility to save our generated QR codes in different file formats such as <code>.svg</code>, <code>.png</code>, <code>.eps</code>, and <code>.pdf</code>.</p>
<p>Here's how you would do that:</p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno
qrcode = segno.make(<span class="hljs-string">'Beatles'</span>)
qrcode.save(<span class="hljs-string">'Beatles.svg'</span>)
qrcode.save(<span class="hljs-string">'Beatles.png'</span>)
qrcode.save(<span class="hljs-string">'Beatles.eps'</span>)
</code></pre>
<h2 id="heading-use-cases-for-qr-codes-with-examples">Use Cases for QR Codes with Examples</h2>
<h3 id="heading-how-to-make-a-qr-code-for-url-sharing">How to Make a QR Code for URL Sharing</h3>
<p>We can easily generate a QR code that links to a URL. This lets us get online content by using the same technique with a little bigger payload.</p>
<p>We will create a QR code that links to my YouTube channel (Velcast Podcast), and then we will save it.</p>
<p>Here's the code for that:</p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno

video = segno.make(<span class="hljs-string">'https://www.youtube.com/channel/UCNhFxpk6hGt5uMCKXq0Jl8A'</span>)
video.save(<span class="hljs-string">'Video.png'</span>, dark=<span class="hljs-string">"yellow"</span>, light=<span class="hljs-string">"#323524"</span>, scale=<span class="hljs-number">5</span>)
</code></pre>
<p>And the result:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/Video.png" alt="Image" width="600" height="400" loading="lazy">
<em>video.png</em></p>
<h3 id="heading-how-to-make-a-qr-code-for-a-wifi-configuration">How to Make a QR Code for a WiFi Configuration</h3>
<p>We can also use the Segmo library to create a QR code for wifi configuration. The <code>segno.helpers</code> module offers factory methods to generate standard QR codes for encoding geographic coordinates, <code>vCards</code> and <code>MeCards</code>, <code>WIFI setups</code>, and <code>EPC QR Codes</code>. </p>
<p>The error correction level "L" is utilized in creating QR codes. If possible, we will apply the higher error correction level without altering the QR Code version.</p>
<p>The density of the QR code picture decreases with decreasing error correction level, which enhances minimum printing size. The more damage it can withstand before losing its ability to be read, the greater the error correction level.</p>
<p>The optimal balance between density and toughness for general marketing use is Level L or Level M. In industrial settings where maintaining a clean or undamaged QR code may be difficult, Level Q and Level H are the best options.</p>
<pre><code class="lang-py"><span class="hljs-keyword">from</span> segno <span class="hljs-keyword">import</span> helpers

qrcode = helpers.make_wifi(ssid=<span class="hljs-string">'MyWifi'</span>, password=<span class="hljs-string">'1234567890'</span>, security=<span class="hljs-string">'WPA'</span>)
qrcode.designator
<span class="hljs-string">'3-M'</span>
qrcode.save(<span class="hljs-string">'wifi-access.png'</span>, scale=<span class="hljs-number">10</span>)
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/12/wifi-access.png" alt="Image" width="600" height="400" loading="lazy">
<em>wifi-access.png</em></p>
<p>We can also do this code this way:</p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> segno
wifi_settings = {    
    ssid=<span class="hljs-string">'(Wifi Name)'</span>,    
    password=<span class="hljs-string">'(Wifi Password)'</span>,    
    security=<span class="hljs-string">'WPA'</span>,
    }
wifi = segno.helpers.make_wifi(**wifi_settings)
wifi.save(<span class="hljs-string">"Wifi.png"</span>, dark=<span class="hljs-string">"yellow"</span>, light=<span class="hljs-string">"#323524"</span>, scale=<span class="hljs-number">8</span>)
</code></pre>
<p>We can use either of the two options for the code. They result in the same thing but represent different styles of writing and presentation.</p>
<p>Common use cases of using QR codes for wifi access include:</p>
<ul>
<li>Instead of giving consumers unique access codes, businesses may use QR codes to offer free WiFi access. Customers only need to scan the code to have access.</li>
<li>Families can use it to grant visitors access to their internet at home.</li>
</ul>
<h3 id="heading-how-to-encode-contact-details-in-qr-codes">How to Encode Contact Details in QR Codes</h3>
<p>We can also store contact details in a QR code. We just need to make use of the <code>helpers.make_mecard()</code> method and we can pass in the contact details. It's also important to note that we can pass in a list to the method.</p>
<p>Let's look at an example:</p>
<pre><code class="lang-py"><span class="hljs-keyword">from</span> segno <span class="hljs-keyword">import</span> helpers
qrcode = helpers.make_mecard(name=<span class="hljs-string">'Shittu Olumide'</span>, email=<span class="hljs-string">'me@example.com'</span>, phone=<span class="hljs-string">'+123456789'</span>)
qrcode.designator
<span class="hljs-string">'3-L'</span>
<span class="hljs-comment"># Some params accept multiple values, like email, phone, url</span>
qrcode = helpers.make_mecard(name=<span class="hljs-string">'Shittu Olumide'</span>, 
                             email=(<span class="hljs-string">'me@example.com'</span>, <span class="hljs-string">'email@example.com'</span>),
                             url=[<span class="hljs-string">'http://www.example.com'</span>, <span class="hljs-string">'https://example.come/~olu'</span>])
qrcode.save(<span class="hljs-string">'mycontact.png'</span>, scale=<span class="hljs-number">5</span>)
</code></pre>
<p>Segno also allows you to perform the following actions:</p>
<ul>
<li><strong>segno.helpers.make_geo</strong>: Launch the built-in mapping program at a certain Latitude and Longitude.</li>
<li><strong>segno.helpers.make_email</strong>: Send a message using a preset topic and body. Excellent for activating any number of potential activities from a mail server, like subscribing to newsletters, registering your arrival somewhere, and more.</li>
<li><strong>segno.helpers.make_epc_qr</strong>: Initiate an electronic payment.</li>
</ul>
<h3 id="heading-qr-code-use-cases">QR code use cases</h3>
<p>Now that you've learned how to create QR codes, here are some of their applications in businesses and in our daily lives:</p>
<ul>
<li>Digital payments.</li>
<li>Sharing business information.</li>
<li>Sharing personal contact information.</li>
<li>QR code menus in restaurants.</li>
<li>Facilitating WiFi authentication.</li>
</ul>
<p>And many more.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Hopefully, this short article has whetted your appetite and inspires you to employ QR codes in your work and personal projects. </p>
<p>By developing some eye-catching, functioning QR codes in this article, we tested the Segno Python module. You can read the official <a target="_blank" href="https://segno.readthedocs.io/en/latest/">documentation</a> to learn more about the library.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Generate QR Codes in Angular 10 ]]>
                </title>
                <description>
                    <![CDATA[ By Ahmed Bouchefra In this tutorial, we'll learn how to generate QR codes in Angular 10 by building a simple example application. But first of all, what's a QR code and what does it do? According to Wikipedia: A QR code (abbreviated from Quick Respo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/generate-qr-codes-in-angular-10/</link>
                <guid isPermaLink="false">66d45d62230dff01669057a3</guid>
                
                    <category>
                        <![CDATA[ Angular ]]>
                    </category>
                
                    <category>
                        <![CDATA[ qr code ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 10 Aug 2020 17:56:29 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9955740569d1a4ca1f23.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ahmed Bouchefra</p>
<p>In this tutorial, we'll learn how to generate QR codes in Angular 10 by building a simple example application.</p>
<p>But first of all, what's a QR code and what does it do?</p>
<p>According to <a target="_blank" href="https://en.wikipedia.org/wiki/QR_code">Wikipedia</a>:</p>
<blockquote>
<p>A QR code (abbreviated from Quick Response code) is a type of matrix barcode (or two-dimensional barcode) first designed in 1994 for the automotive industry in Japan.   </p>
<p>A barcode is a machine-readable optical label that contains information about the item to which it is attached.   </p>
<p>In practice, QR codes often contain data for a locator, identifier, or tracker that points to a website or application.   </p>
<p>A QR code uses four standardized encoding modes (numeric, alphanumeric, byte/binary, and kanji) to store data efficiently.</p>
</blockquote>
<p>So it's simply a compact and efficient way of storing data.</p>
<p>Now let's see how to generate QR codes in your Angular 10 apps by creating an example.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before getting started you need a few prerequisites:</p>
<ul>
<li>Basic knowledge of TypeScript. Particularly the familiarity with Object Oriented concepts such as TypeScript classes and decorators.</li>
<li>A local development machine with <strong>Node 10+</strong>, together with <strong>NPM 6+</strong> installed.</li>
</ul>
<p>Node is required by the Angular CLI like the most front end tools nowadays. You can simply go to the downloads page of <a target="_blank" href="https://nodejs.org/downloads">the official website</a> and download the binaries for your operating system. </p>
<p>You can also refer to your specific system instructions for how to install Node using a package manager. The recommended way though is using <a target="_blank" href="https://github.com/nvm-sh/nvm">NVM</a> — Node Version Manager — a POSIX-compliant bash script to manage multiple active Node.js versions.</p>
<p><strong>Note</strong>: Don't want to install a local environment for Angular development but still want to try the code in this tutorial? You can use <a target="_blank" href="https://stackblitz.com/">Stackblitz</a>, an online IDE for frontend development that lets you create an Angular project compatible with the Angular CLI.</p>
<h2 id="heading-step-1-installing-angular-cli-10">Step 1 — Installing Angular CLI 10</h2>
<p>In this step, we'll <a target="_blank" href="https://www.ahmedbouchefra.com/install-angular-cli/">install the latest Angular CLI 10</a> (at the time of writing this tutorial).</p>
<p><a target="_blank" href="https://cli.angular.io/">Angular CLI</a> is the official tool for initializing and working with Angular projects. To install it, open a new command-line interface and run the following command:</p>
<pre><code class="lang-bash">$ npm install -g @angular/cli
</code></pre>
<p>At the time of writing, <strong>angular/cli v10</strong> will be installed on your system.</p>
<h2 id="heading-step-2-creating-a-new-angular-10-app"><strong>Step 2 — Creating a New Angular 10 App</strong></h2>
<p>Let's now create our project. Head back to your command-line interface and run the following commands:</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">cd</span> ~
$ ng new angular10qrcode
</code></pre>
<p>The CLI will ask you a couple of questions:</p>
<ul>
<li><strong>Would you like to add Angular routing?</strong> Type <strong>y</strong> for Yes, and </li>
<li><strong>Which stylesheet format would you like to use?</strong> Choose <strong>CSS</strong>.</li>
</ul>
<p>Next, navigate to you project’s folder and run the local development server using the following commands:</p>
<pre><code class="lang-bash">$ <span class="hljs-built_in">cd</span> angular10qrcode
$ ng serve
</code></pre>
<p>Open your web browser and navigate to the <code>http://localhost:4200/</code> address to see your app running.</p>
<p>Next, open a new terminal and make sure to navigate to your project's folder and run the following command to install the <a target="_blank" href="https://github.com/techiediaries/ngx-qrcode"><code>ngx-qrcode</code> library</a> from npm using the following command:</p>
<pre><code class="lang-bash">$ npm install @techiediaries/ngx-qrcode
</code></pre>
<p>Next open the <code>src/app/app.module.ts</code> file, and import <code>NgxQRCodeModule</code> from <code>@techiediaries/ngx-qrcode</code> in your module as follows:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { BrowserModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/platform-browser'</span>;
<span class="hljs-keyword">import</span> { NgModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
<span class="hljs-keyword">import</span> { NgxQRCodeModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@techiediaries/ngx-qrcode'</span>;
<span class="hljs-keyword">import</span> { FormsModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/forms'</span>;


<span class="hljs-keyword">import</span> { AppComponent } <span class="hljs-keyword">from</span> <span class="hljs-string">'./app.component'</span>;

<span class="hljs-meta">@NgModule</span>({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    NgxQRCodeModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> AppModule { }
</code></pre>
<p>Once the library has been imported, you can use the <code>ngx-qrcode</code> component in your Angular application.</p>
<blockquote>
<p>Please note that we have also imported the <code>FormsModule</code>.</p>
</blockquote>
<p>Next, open the <code>src/app/app.component.ts</code> file and update it as follows:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { Component } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
<span class="hljs-keyword">import</span> { NgxQrcodeElementTypes, NgxQrcodeErrorCorrectionLevels } <span class="hljs-keyword">from</span> <span class="hljs-string">'@techiediaries/ngx-qrcode'</span>;

<span class="hljs-meta">@Component</span>({
  selector: <span class="hljs-string">'my-app'</span>,
  templateUrl: <span class="hljs-string">'./app.component.html'</span>,
  styleUrls: [ <span class="hljs-string">'./app.component.css'</span> ]
})
<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> AppComponent  {
  elementType = NgxQrcodeElementTypes.URL;
  correctionLevel = NgxQrcodeErrorCorrectionLevels.HIGH;
  value = <span class="hljs-string">'https://www.techiediaries.com/'</span>;
}
</code></pre>
<p>Next, open the <code>src/app/app.component.html</code> file and add the following code:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ngx-qrcode</span>
  [<span class="hljs-attr">elementType</span>]=<span class="hljs-string">"elementType"</span>
  [<span class="hljs-attr">errorCorrectionLevel</span>]=<span class="hljs-string">"correctionLevel"</span>
  [<span class="hljs-attr">value</span>]=<span class="hljs-string">"value"</span>
  <span class="hljs-attr">cssClass</span>=<span class="hljs-string">"bshadow"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ngx-qrcode</span>&gt;</span>
</code></pre>
<p> We use various properties for configuring our QR code such as:</p>
<ul>
<li>the type, </li>
<li>the error correction level,</li>
<li>the value,</li>
<li>the CSS class.</li>
</ul>
<p>You can find out more information about these properties and the other supported properties from the official <a target="_blank" href="https://www.techiediaries.com/ngx-qrcode/"><code>ngx-qrcode</code></a> <a target="_blank" href="https://www.techiediaries.com/ngx-qrcode/">docs</a>.</p>
<p>Next, add a textarea for entering the value that you want to encode:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">textarea</span> [(<span class="hljs-attr">ngModel</span>)] = <span class="hljs-string">"value"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">textarea</span>&gt;</span>
</code></pre>
<p>Finally open the <code>src/styles.css</code> file and add the following styles:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.bshadow</span> {

  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">filter</span>: <span class="hljs-built_in">drop-shadow</span>(<span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> #<span class="hljs-number">222222</span>);
  <span class="hljs-attribute">opacity</span>: .<span class="hljs-number">5</span>;

}

<span class="hljs-selector-tag">textarea</span> {
    <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">15px</span>; 
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">margin-left</span>: auto;
    <span class="hljs-attribute">margin-right</span>: auto;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">250px</span>;
    <span class="hljs-attribute">opacity</span>: .<span class="hljs-number">5</span>;
}
</code></pre>
<p>This is a screenshot of our application:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/Screenshot-from-2020-08-06-20-26-36.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>That's it we have finished our Angular 10 example project that demonstrates how to generate QR codes. </p>
<p>You can visit us on <strong><code>Techiediaries</code></strong> for tutorials about Angular and modern web development practices.</p>
<p>You can check out the application we've built in this article live on Stackblitz:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://stackblitz.com/edit/angular-ngx-qrcode-example?file=src%2Fapp%2Fapp.component.ts">https://stackblitz.com/edit/angular-ngx-qrcode-example?file=src%2Fapp%2Fapp.component.ts</a></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use QR Codes for Effective Marketing and Outreach ]]>
                </title>
                <description>
                    <![CDATA[ By Black Raven Efficient means doing things right. Effective is about doing the right things. I am an advocate for efficiency and effectiveness. There must be a more efficient way to share contact details other than manually typing details into my mo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/making-use-of-qr-codes-for-effective-marketing-and-reach/</link>
                <guid isPermaLink="false">66d45dd951f567b42d9f8439</guid>
                
                    <category>
                        <![CDATA[ industry 4.0 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ business strategy ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #content marketing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Digital Transformation ]]>
                    </category>
                
                    <category>
                        <![CDATA[ qr code ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 27 Mar 2020 21:53:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/03/Screenshot_1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Black Raven</p>
<p><strong>Efficient</strong> means doing things right. <strong>Effective</strong> is about doing the right things.</p>
<p>I am an advocate for efficiency and effectiveness. There must be a more efficient way to share contact details other than manually typing details into my mobile phone when I meet a new business contact.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/image-187.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Name cards with QR Code</em></p>
<h1 id="heading-add-a-new-contact-on-your-mobile-phone-by-scanning-a-qr-code">Add a new contact on your mobile phone by scanning a QR Code</h1>
<p>When Google launched the <strong>Google Contacts</strong> app in 2017, users could share contact information with QR codes. To add a new contact, simply scan a person's QR code to save their contact information on your phone.</p>
<p>I personally think that such an efficient way to save contact details should be implemented on business cards and marketing brochures.</p>
<p>The trend did not seem to take off, maybe because people did not know how to create the QR Codes in the first place.</p>
<h2 id="heading-create-a-list-of-customized-contacts-qr-codes">Create a list of customized contacts QR Codes</h2>
<p>I made use of a <strong>Google Sheets</strong> template to generate the contact QR codes.</p>
<p>Open the template (<a target="_blank" href="https://docs.google.com/spreadsheets/d/1jJdBgqQvYuQM-Bo0An2W7CUS5c4EQKjyRkHYZln3Wr0/edit?usp=sharing">template link here</a>) in another tab. Then click on “File -&gt; Make a copy” to save it to your own "My Drive" (Google Drive account).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/1_grwBMqbnT87naQki630AtA.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Google Sheets template to generate the contact QR codes</em></p>
<p><em>Note that this Google Sheets template seems to only work on desktops, not on mobile phones.</em></p>
<p>You can use this template by updating <strong>First Name</strong>, <strong>Last Name</strong>, <strong>Mobile Phone</strong> number and <strong>Email address</strong>. The contact QR Code will be generated in the next column based on these 4 fields.</p>
<pre><code class="lang-excel">=image(“htt<span class="hljs-symbol">ps:</span>//chart.googleapis.com/chart?chs=<span class="hljs-number">150</span>x150&amp;cht=qr&amp;chl=BEG<span class="hljs-symbol">IN:VC</span>ARD%<span class="hljs-number">0</span><span class="hljs-symbol">AN:</span><span class="hljs-string">" &amp; A3 &amp; “%20” &amp; B3 &amp; “%0ATEL;CELL:” &amp; C3 &amp; “%0AEMAIL:” &amp; D3 &amp; “%0AEND:VCARD”)</span>
</code></pre>
<p>Then another person can scan the generated QR code to add the contact details to their phone.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/1_fZzgOk0-Mc-zTzc3lCuGzA.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>New iOS and Android versions are equipped with QR Code scanner in camera mode</em></p>
<p>After scanning, simply click on “Save” to add the information to Contacts.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/1_tkEkTu94w7CBhVhMat1aCA.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Scan QR code and save contact</em></p>
<p>This contact list QR Code template will be useful when you meet new people in a team or at a tradeshow and want to gather everyone’s contact details.</p>
<h2 id="heading-to-create-a-single-customized-contacts-qr-code">To create a single customized contacts QR Code</h2>
<p>Go to <a target="_blank" href="https://www.qr-code-generator.com/">QR Code Generator</a>, and select ‘vCard’ where you can customize various fields. Remember to test it out, as some fields do not allow special characters like "," or "@".</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/1_q5Yxh3Yrq_XSweBRBOLKtg.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><a target="_blank" href="https://www.qr-code-generator.com/"><em>https://www.qr-code-generator.com/</em></a></p>
<p>You can also add this QR code to your business cards and marketing brochures. Customers and business people can then easily scan and save your contact details to their mobile phones.</p>
<h1 id="heading-go-to-a-website-by-scanning-a-qr-code">Go to a website by scanning a QR Code</h1>
<p>Newer versions of iPhone and Android phones are equipped with QR code scanning in the camera app. Simply turn on the camera and hover over the QR Code to scan it. Then you can click the popup to go to the web address URL embedded.</p>
<p>For example, try to scan this QR code:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/1_8Rk_gKSDJVfafeWiullsWw.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Web URL embedded</em> <a target="_blank" href="https://www.qrcode-monkey.com"><em>https://www.qrcode-monkey.com</em></a></p>
<h2 id="heading-to-create-your-own-customized-qr-codes">To create your own customized QR Codes</h2>
<p>I usually go to <a target="_blank" href="https://www.qrcode-monkey.com/">QR Code Monkey</a> to create a customized QR codes. It is friendly and <strong>free to use</strong>, and there are more options if you want to:</p>
<ul>
<li><p>add a logo image in the middle (this can be your <strong>company logo</strong>!)</p>
</li>
<li><p>set a color (to follow your <strong>corporate identity</strong>)</p>
</li>
<li><p>use some other other customized design</p>
</li>
</ul>
<p>So now you can easily create marketing materials with QR code of your company's website.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/1_-_nSVy6PxwJ9XKzU1PZ9iA.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Marketing materials with QR codes</em></p>
<hr>
<h2 id="heading-qr-codes-for-name-cards-and-marketing-brochures">QR Codes for name cards and marketing brochures</h2>
<p>I hope the tips above are useful for getting things done more efficiently and effectively. All the best to your marketing and outreach efforts!</p>
<p>Thank you for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
