<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: shahriarKabir44</title>
    <description>The latest articles on Forem by shahriarKabir44 (@shahriarkabir44).</description>
    <link>https://forem.com/shahriarkabir44</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%2F549847%2Ff8f185db-6b2a-4f3b-8a9e-e79f5ae621c3.png</url>
      <title>Forem: shahriarKabir44</title>
      <link>https://forem.com/shahriarkabir44</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/shahriarkabir44"/>
    <language>en</language>
    <item>
      <title>Send Push Notifications Using Vanila JS! (Example with ExpressJS)</title>
      <dc:creator>shahriarKabir44</dc:creator>
      <pubDate>Tue, 20 Jan 2026 19:58:24 +0000</pubDate>
      <link>https://forem.com/shahriarkabir44/send-push-notifications-using-vanila-js-example-with-expressjs-36jp</link>
      <guid>https://forem.com/shahriarkabir44/send-push-notifications-using-vanila-js-example-with-expressjs-36jp</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Making a lucrative UI or smooth UX are no longer enough to keep your clients attracted to you now-a-days! You need more. You need User Engagement. Specially if you're selling something online, an e-commerce perhaps. And you want to inform your users about a big sale that's coming on a specific festival. How? You might think that if you had an app, you might send your users some push notifications. Which is true but not really feasible in many cases specially when you're new to business. and then you wonder..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; What if a web application could send push notificatons? 🤔
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Well lucky you because you're at the right spot!&lt;/p&gt;
&lt;h1&gt;
  
  
  In this article we'll...
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Do some basics.&lt;/li&gt;
&lt;li&gt;Create a simple web app with frontend and backend.&lt;/li&gt;
&lt;li&gt;Dive a bit deep on how it works.&lt;/li&gt;
&lt;li&gt;Some FAQs 🤓&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, let's go!&lt;/p&gt;
&lt;h2&gt;
  
  
  Environment Setup.
&lt;/h2&gt;

&lt;p&gt;Fire up your vscode in a folder and create a js file. This will be the server part from where we'll send the notifications. Now create a new project using npm with the command&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will create a package.json file for you.&lt;br&gt;
we need to install 2 npm packages.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;b&gt; dotenv &lt;/b&gt; To store private and public VAPID key. (More on these later)&lt;/li&gt;
&lt;li&gt;
&lt;b&gt; web-push &lt;/b&gt; To actually send the notifications.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Install them with the &lt;code&gt;npm install&lt;/code&gt; command.&lt;/p&gt;
&lt;h3&gt;
  
  
  The plan (Bird's Eye View):
&lt;/h3&gt;

&lt;p&gt;There are two major players in this game. &lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API" rel="noopener noreferrer"&gt;ServiceWorkers&lt;/a&gt; and Web-Push&lt;br&gt;
At first, we need to create to two keys which are called VAPID (Voluntary Application Server Identification) keys one is public and another is private (Asymmetric encryption/decryption but let's not dig deeper here).&lt;br&gt;
The idea is that we register a serviceworker and use the subscription object to create a &lt;code&gt;PushSubscription&lt;/code&gt; object using the public VAPID key.&lt;br&gt;
We then send this object to the backend with a POST request. The server stores it. And in any event, the server uses the client's subscription object to send the notification.&lt;br&gt;
In short...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fykuuhcheobrini1qguqs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fykuuhcheobrini1qguqs.png" alt="Data Flow"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Enough with the chit chat!
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhczdsni51mpst5gafe1j.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhczdsni51mpst5gafe1j.gif" alt="Let's Move!"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Project Structure:
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root/
├── client/
│   ├── index.html
│   ├── index.js
│   └── worker.js 
├── app.js
├── .env
├── package.json
└── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  The Frontend:
&lt;/h2&gt;
&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;

&lt;p&gt;We'll keep it as simple as possible. We're only interested on getting a push notification on a button click. No fancy design, no CSS. Just a single button in HTML.&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;h3&gt;
  
  
  ServiceWorker
&lt;/h3&gt;

&lt;p&gt;We'll limit our serviceworker's role to just receiving push notifications and show it.&lt;br&gt;
A notification needs to have three properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Icon&lt;/li&gt;
&lt;li&gt;Title&lt;/li&gt;
&lt;li&gt;Body
So, we'll design our payload object keeping this in mind. We'll use a fixed notification icon in this demonstration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;br&gt;
Nicely done!
&lt;h2&gt;
  
  
  The backend
&lt;/h2&gt;

&lt;p&gt;Let's do the bare minimum in our backend part in our &lt;code&gt;app.js&lt;/code&gt; file. &lt;br&gt;
Such as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Including the necessary packages.&lt;/li&gt;
&lt;li&gt;Configuring the port.&lt;/li&gt;
&lt;li&gt;Pointing the static files directory.&lt;/li&gt;
&lt;li&gt;Configuring the environment variable. (We'll store our keys in the .env file btw)&lt;/li&gt;
&lt;li&gt;And an API endpoint to receive and store the client's info.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;




&lt;p&gt;Great! now the crucial part! &lt;/p&gt;

&lt;h2&gt;
  
  
  Generating the VAPID keys
&lt;/h2&gt;

&lt;p&gt;Run the following command on your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx web-push generate-vapid-keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You'll get an output like this..&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=======================================

Public Key:
&amp;lt;Public Key&amp;gt;

Private Key:
&amp;lt;Private Key&amp;gt;

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

&lt;/div&gt;


&lt;p&gt;Copy the keys and store them in your &lt;code&gt;.env&lt;/code&gt; file.&lt;br&gt;
Now, we register the ServiceWorker. &lt;br&gt;
Here's what we'd do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Register the ServiceWorker (worker.js in our case)&lt;/li&gt;
&lt;li&gt;Create Push Subscription.
 2.1. Convert the public VAPID key to Uint8 Array.
 2.2. Create the PushSubscription object&lt;/li&gt;
&lt;li&gt;Post it to the backend.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Like so..&lt;br&gt;


&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;I'm sure that you're wondering what's happening in the following code:&lt;/p&gt;

&lt;pre&gt;
 function convertToUnit8Array(base64str) {
    const padding = '='.repeat((4 - (base64str.length % 4)) % 4)
    const base64 = (base64str + padding).replace(/\-/g, '+').replace(/_/g, '/')
    const rawData = atob(base64)
    var outputArray = new Uint8Array(rawData.length)
    for (let n = 0; n &amp;lt; rawData.length; n++) {
        outputArray[n] = rawData.charCodeAt(n)
    }
    return outputArray
}
&lt;/pre&gt;

&lt;p&gt;What it does is basically &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pad the string with '=' character to make its length divisible by 4. &lt;/li&gt;
&lt;li&gt;Convert Base64URL → normal Base64&lt;/li&gt;
&lt;li&gt;Decode Base64 → raw binary string
Basically, converting the human readable public key to machine readable byte array.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let's update our server code, shall we?&lt;/p&gt;

&lt;p&gt;We'll configureour webpush with our public and private VAPID keys and an email address. For now, we're not providing any valid email. &lt;br&gt;
 We'll also implement a get API called &lt;code&gt;/sendNofication&lt;/code&gt; to send a notification to the client.&lt;br&gt;
 Here's the updated code:&lt;br&gt;
 

&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;br&gt;
Great! We're now ready!&lt;br&gt;
Fire up your server with the following command:

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

&lt;/div&gt;

&lt;p&gt;And open your browser on the following URL:&lt;br&gt;
&lt;a href="http://localhost:4000/" rel="noopener noreferrer"&gt;localhost:4000&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And follow me!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43u0dun6ijs4j7q71jv2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43u0dun6ijs4j7q71jv2.gif" alt="Demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;BOOM! We've implemented push notifications!&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6f2wihby01u8xw7hxgk.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz6f2wihby01u8xw7hxgk.gif" alt="enter image description here"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQs:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Is it scalable?&lt;/strong&gt; &lt;br&gt;
     HELL YEAH 💪 It's the push notification services that does the main heavy lifting. Not you! (E.g. Google, Firefox, Apple etc depending on the browser). If you inspect the PushSubscription object, you'll find a property called &lt;code&gt;endpoint&lt;/code&gt;. When your server wants to send you a push notification, it basically becomes a REST API client and calls API mentioned in the endpoint property.&lt;br&gt;
&lt;strong&gt;Do you have to manage any states?&lt;/strong&gt; &lt;br&gt;
    You might think that since it's real-time, you'll have to store some state in the server like WebSocket. Luckily that's not the case. You only need to store the user's subscription data in the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;So, we've implemented push notifications using vanilla js! Please let me know how I can improve this article. &lt;br&gt;
Here's the entire codebase btw if you're interested:&lt;br&gt;
&lt;a href="https://github.com/shahriarKabir44/push_notification_using_nodejs" rel="noopener noreferrer"&gt;Git Repository&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>serviceworkers</category>
      <category>pushnotifications</category>
    </item>
    <item>
      <title>Browser Dev Tools for Mobile!</title>
      <dc:creator>shahriarKabir44</dc:creator>
      <pubDate>Mon, 24 Nov 2025 17:46:33 +0000</pubDate>
      <link>https://forem.com/shahriarkabir44/browser-dev-tools-for-mobile-3nc8</link>
      <guid>https://forem.com/shahriarkabir44/browser-dev-tools-for-mobile-3nc8</guid>
      <description>&lt;h1&gt;
  
  
  Browser Dev Tools for Mobile!
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Modern day web browsers provide an important tool that we, web devs love and live for. The DevTools. We use it for&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debugging the JavaScript code on the client side.&lt;/li&gt;
&lt;li&gt;Test and tweak the styles.&lt;/li&gt;
&lt;li&gt;View the webpage in 3D to understand z-index.&lt;/li&gt;
&lt;li&gt;Intercepting HTTP requests.&lt;/li&gt;
&lt;li&gt;View the webpage on different devices' screen dimensions.
Basically, it's the Swiss Army Knife that makes our lives easier. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  BUT!!
&lt;/h2&gt;

&lt;p&gt;How about doing the same stuff on the mobile devices? What if there's a bug that's showing up in only the mobile devices? Well, I personally have run into such cases several times and there's honestly no mobile App that's going to save our bum or at least make things easy. Well good news for us because I've found an approach that honestly blew my mind! &lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;I'm using my Android Smartphone as I write this article. And we'll be using Chrome browser. This approach has a tiny prerequisite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to have developer options enabled on your smartphone before you proceed.&lt;/li&gt;
&lt;li&gt;Both your PC and your smartphone should be under the same network.&lt;/li&gt;
&lt;li&gt;We'll be using the Chrome Browser for this article. This means that you'll be needing Chrome both your PC and your smartphone.
That's it!
Now let's go step by step, shall we?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 1:
&lt;/h3&gt;

&lt;p&gt;Connect your smartphone with your computer with a USB cable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2:
&lt;/h3&gt;

&lt;p&gt;Open Chrome browser on your PC and type the following URL on the URL bar:&lt;br&gt;
 &lt;code&gt;chrome://inspect/#devices&lt;/code&gt;&lt;br&gt;
 And you'll get a view like the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwa3zwllsd0o7nde63iz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwa3zwllsd0o7nde63iz8.png" alt=" " width="800" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3:
&lt;/h3&gt;

&lt;p&gt;Now, once you connect your phone with your PC, you'll see the following message on your notification tray. Click on it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpt1q2pp0lq3dskmem8y1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpt1q2pp0lq3dskmem8y1.jpg" alt=" " width="720" height="779"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4:
&lt;/h3&gt;

&lt;p&gt;Search for Wireless Debugging. Then allow it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgt6rsvebpgwlw5mivtdt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgt6rsvebpgwlw5mivtdt.jpg" alt=" " width="720" height="738"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5:
&lt;/h3&gt;

&lt;p&gt;Now open your chrome browser from your phone and open any website. Then look at your PC's chrome browser and you'll find all the tabs opened on your phone. Like so.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8r93w8eas3spxa35105n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8r93w8eas3spxa35105n.png" alt=" " width="800" height="455"&gt;&lt;/a&gt;&lt;br&gt;
As you can see, I have opened W3School's JavaScript Tutorial article's page.&lt;br&gt;
Now go ahead and hit &lt;code&gt;inspect&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe84apsim44609b9xwoj7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe84apsim44609b9xwoj7.png" alt=" " width="800" height="440"&gt;&lt;/a&gt;&lt;br&gt;
Voila!! 🥳🥳 You've got the DevTools to inspect your website from your mobile! What's even crazier is that you can also interact with the website form your PC and do whatever you want with the DevTool!!&lt;/p&gt;

&lt;p&gt;And if you have come this far, thank you so much! Please let me know if I missed anything! Peace ✌ &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devtool</category>
      <category>browser</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
