<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Girish Venkatachalam on Medium]]></title>
        <description><![CDATA[Stories by Girish Venkatachalam on Medium]]></description>
        <link>https://medium.com/@girish1729?source=rss-1db55faeafb0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2blFLovHo1tqiQPI.jpeg</url>
            <title>Stories by Girish Venkatachalam on Medium</title>
            <link>https://medium.com/@girish1729?source=rss-1db55faeafb0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 07:35:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@girish1729/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Upload file and fill up HTML form with express multer backend]]></title>
            <link>https://medium.com/@girish1729/upload-file-and-fill-up-html-form-with-express-multer-backend-9e731219508a?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e731219508a</guid>
            <category><![CDATA[express-js-multer]]></category>
            <category><![CDATA[file-upload]]></category>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Mon, 04 May 2026 12:16:22 GMT</pubDate>
            <atom:updated>2026-05-04T12:16:22.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0rSXqQvBUBjDgmrWtBZZ4Q.png" /><figcaption>File upload and form filling</figcaption></figure><p>Here we are checking out how to use express with multer backend to do a file upload and also show preview of image MIME type and use an iframe for PDF uploads.</p><p>Then we save the upload into the <strong>uploads</strong>/ folder.</p><p>We also have a support backend that inspects the redis JSON tickets in a HTML table.</p><p>Once you click at a table row it zooms into a support ticket expanded view and then we can close the ticket with appropriate get request to the express backend.</p><p>You could do a node-mailer or some email automation using postmark transactional email or something to trigger at support creation and closure.</p><p>Here is the gist.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e4ea23a7eca8c5842f401484e4284bf/href">https://medium.com/media/7e4ea23a7eca8c5842f401484e4284bf/href</a></iframe><h3>Conclusion</h3><p>We need not use any ticketing tool for simple support submission.</p><p>This one can do the job nicely enough.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e731219508a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Loading html templates using jQuery]]></title>
            <link>https://medium.com/@girish1729/loading-html-templates-using-jquery-d57965ed319e?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d57965ed319e</guid>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Sat, 02 May 2026 02:44:17 GMT</pubDate>
            <atom:updated>2026-05-02T02:44:17.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzpzBe2t3MkdQdnaIFaj9A.png" /><figcaption>HTML template tag</figcaption></figure><p>I used to load html templates for each page on my web application using this code without using jQuery before.</p><p>This is plain JS.</p><pre>loadTemplate = async function(filename) {<br>    const res = await fetch(filename)<br>    const text = await res.text()<br>    document.body.insertAdjacentHTML(&#39;beforeend&#39;, text)<br>    return document.body.lastElementChild<br>}<br><br>function addTemplates() {<br>    let main = document.querySelector(&#39;#main-content&#39;);<br>    Promise.all([<br>        this.loadTemplate(&#39;./templates/overview.tpl&#39;),<br>        this.loadTemplate(&#39;./templates/apikey.tpl&#39;),<br>        this.loadTemplate(&#39;./templates/analytics.tpl&#39;),<br>    ]).then(templates =&gt; {<br>        templates.forEach(el =&gt; {<br>            let clone = el.content.cloneNode(true);<br>            main.appendChild(clone);<br>        });<br>        hideAllPages();<br>    })<br>}<br><br></pre><p>It worked for HTML elements and template code and also styling though the namespace pollution occurred, so you have to still name your CSS classes properly.</p><p>However I could not have script tags inside the template tag for each page and that was a hassle.</p><p>I solved that by dumping above code and using Query 4.0.0 this way.</p><pre>let templates = [<br>    &#39;./templates/overview.tpl&#39;,<br>    &#39;./templates/apikey.tpl&#39;,<br>    &#39;./templates/analytics.tpl&#39;,<br>    &#39;./templates/billing.tpl&#39;,<br>    &#39;./templates/settings.tpl&#39;,<br>    &#39;./templates/schedules.tpl&#39;,<br>    &#39;./templates/support.tpl&#39;,<br>    &#39;./templates/history.tpl&#39;,<br>    &#39;./templates/gallery.tpl&#39;,<br>    &#39;./templates/billing.tpl&#39;,<br>];<br><br>    $(&#39;body&#39;).append(&#39;&lt;div id=&quot;template-holder&quot; style=&quot;display:none;&quot;&gt;&lt;/div&gt;&#39;);<br>    $.each(templates, function(index, url) {<br>        $(&#39;#template-holder&#39;).load(url, function() {<br>            let templateContent = $(&#39;#template-holder&#39;).children().clone();<br>            let clone = templateContent.html();<br>            $(&#39;#main-content&#39;).append(clone);<br>            console.log(`template ${url} loaded`);<br>        });<br>        hideAllPages();<br>    });<br><br></pre><p>You can ignore hideAllPages(), just a function to use CSS hiding as they all get loaded into the main tag area.</p><p>On each button click I unhide that ID and hide all others.</p><p>Now with this innovation I can have script tags inside templates thereby doing actual code containment.</p><p>I am yet to figure out real time analytics, graphing and other stuff using CORS for these views to update dynamically from my moroJS API backend.</p><p>That is for another time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d57965ed319e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple fill and stroke of html5 canvas objects using input color element]]></title>
            <link>https://towardsdev.com/simple-fill-and-stroke-of-html5-canvas-objects-using-input-color-element-0e20765328f5?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e20765328f5</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[html-css]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Sat, 03 Jan 2026 13:22:24 GMT</pubDate>
            <atom:updated>2026-01-03T13:22:24.729Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zSSjmRGyhD40I81ePmN1eA.png" /><figcaption>Simple fill and stroke</figcaption></figure><p>In html5 canvas there is very simple need to fill and stroke with the right color.</p><p>I wished to achieve this using a color input html element and some JavaScript code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b0a2c15319d560f37b64618d4cdb137/href">https://medium.com/media/3b0a2c15319d560f37b64618d4cdb137/href</a></iframe><p>As you can see from the code above you can get a color change of the shapes either by changing the input color selector or by clicking at the shape after changing the color using the color dialog.</p><h3>Conclusion</h3><p>A bucket fill is typically used in image editing and this code helps you achieve just that.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e20765328f5" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/simple-fill-and-stroke-of-html5-canvas-objects-using-input-color-element-0e20765328f5">Simple fill and stroke of html5 canvas objects using input color element</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using overlay checkout in Paddle and configuring webhook for one time payments]]></title>
            <link>https://medium.com/@girish1729/using-overlay-checkout-in-paddle-and-configuring-webhook-for-one-time-payments-3ea02f099624?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ea02f099624</guid>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Fri, 02 Jan 2026 03:04:05 GMT</pubDate>
            <atom:updated>2026-01-03T21:27:45.441Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLeWGZAU8x1V6rxRhBksCQ.gif" /><figcaption>Paddle checkout video</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jx5lXHWc4XdGGPpZk_J0pg.png" /><figcaption>Paddle screen</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4tiNwwazFOz-C6QizoI83Q.png" /><figcaption>Our pricing page on our website</figcaption></figure><h3>Introduction</h3><p>We are doing a total lowdown on Paddle payments, including the overlay checkout from payment page on frontend and a webhook backend with user DB (redis) to store transaction details.</p><p>We need that to check if the gmail account that uses our Chrome plugin is a free user or a premium user.</p><p>We are only going to use one time payments. Doing subscriptions is going to be more work.</p><p>Let us begin.</p><h3>Topics we are going to cover</h3><ul><li><strong>How paddle works</strong></li><li><strong>What is a webhook?</strong></li><li><strong>nginx configuration for webhook</strong></li><li><strong>Building pricing page for Paddle payments</strong></li><li><strong>Express.js API and redis user DB for webhook</strong></li><li><strong>Sample source for every topic</strong></li></ul><h3>How paddle works</h3><p>Paddle is not Stripe, it charges more and it is merchant of accounts. I do not know much more, I am a techie.</p><p>Paddle has extensive documentation, API support, sandbox testing facility and even simulations for various scenarios.</p><p>How it works is intuitive in that you have a web frontend to collect payments, you include this JS library in your source code.</p><pre>    &lt;script src=&quot;https://cdn.paddle.com/paddle/v2/paddle.js&quot;&gt;&lt;/script&gt;</pre><p>The actual payment logic is quite easy and short.</p><p>Here is my code(adapted from official source of Paddle).</p><pre>        Paddle.Environment.set(&quot;sandbox&quot;);<br>        Paddle.Initialize({<br>            token: &quot;test_317b2980cd12507682cbfd704c2&quot;,<br>            eventCallback: function(data) {<br>                console.log(data);<br>            }<br>        });<br><br>        let screenshot_productId = &quot;pro_01kcrmmxy0qpxz2zx12fd6s0p6&quot;;<br>        let Screenshot_itemsList = [{<br>            priceId: &quot;pri_01kcrms2h1wgs52p5e0d7ff2ga&quot;,<br>            quantity: 1<br>        }, ];<br><br>        let qr_productId = &quot;pro_01kdmcd1e083gjk6wafr29b2et&quot;;<br>        let QR_itemsList = [{<br>            priceId: &quot;pri_01kdmchkja8v9hrkd1jg1q8nqg&quot;,<br>            quantity: 2,<br>        }, ];<br><br>        let myemail = &quot;girish@photoveda.pro&quot;;<br><br>        // open checkout<br>        function openCheckout(itemsList, customerInfo, email, productID, plan, prodName) {<br>            Paddle.Checkout.open({<br>                customData: {<br>                    email: customerInfo.email,<br>                    name: customerInfo.name,<br>                    productId: productID,<br>                    plan: plan,<br>                    product: prodName,<br>                },<br>                items: itemsList,<br>                product: productID,<br>                customer: customerInfo,<br>                email: email,<br>                successCallback: function(data) {<br>                    alert(&quot;Thank you for your purchase!&quot;);<br>                    webhook();<br>                },<br>                closeCallback: function() {<br>                    alert(&quot;Checkout closed.&quot;);<br>                }<br>            });<br>        }<br>        // Function to handle the POST request<br>        function webhook(payload) {<br>            fetch(&#39;https://api.photoveda.pro/paddle/paddle-webhook&#39;, {<br>                    method: &#39;POST&#39;,<br>                    headers: {<br>                        &#39;Content-Type&#39;: &#39;application/json&#39;,<br>                    },<br>                })<br>                .then(response =&gt; response.json())<br>                .then(data =&gt; {<br>                    console.log(&#39;Payment data sent successfully:&#39;, data);<br>                })<br>                .catch((error) =&gt; {<br>                    console.error(&#39;Error sending payment data:&#39;, error);<br>                });<br>        }</pre><p>Now that we are this far let us also look at the short webhook code that verifies paddle signature(hashed sha256) and how I use redis hook inside the webhook in express.js.</p><pre>app.post(&#39;/paddle-webhook&#39;, express.raw({<br>    type: &#39;application/json&#39;<br>}), async function(req, res) {<br>    const signature = req.headers[&#39;paddle-signature&#39;] || &#39;&#39;;<br>    // req.body should be of type `buffer`, convert to string before passing it to `unmarshal`. <br>    // If express returned a JSON, remove any other middleware that might have processed raw request to object<br>    const rawRequestBody = req.body.toString();<br>    customLogger.log(JSON.stringify(JSON.parse(rawRequestBody), null, 2));<br><br>    try {<br>        if (signature &amp;&amp; rawRequestBody) {<br>            // Parse the webhook<br>            const webhook = parseWebhookBody(<br>                null,<br>                secret,<br>                signature,<br>                // ⚠️ the body must be raw string to parse!<br>                req.body.toString()<br>            );<br>            // If the webhook is invalid, it will be null<br>            if (!webhook) {<br>                res.status(400).send(&quot;Bad Request&quot;);<br>                return;<br>            }<br>            // The `unmarshal` function will validate the integrity of the webhook and return an entity<br>            const eventData = await paddle.webhooks.unmarshal(rawRequestBody, secret, signature);<br>            switch (eventData.eventType) {<br>                case EventName.ProductUpdated:<br>                    console.log(`Product ${eventData.data.id}  updated`);<br>                    break;<br>                case EventName.SubscriptionUpdated:<br>                    console.log(`Subscription ${eventData.data.id}  updated`);<br>                    break;<br>                case EventName.TransactionCreated:<br>                    console.log(`Transaction ${eventData.data.id}  created`);<br>                    break;<br>                case EventName.TransactionReady:<br>                    console.log(`Transaction ${eventData.data.id}  ready`);<br>                    break;<br>                case EventName.TransactionCompleted:<br>                    console.log(`Transaction ${eventData.data.id}  completed`);<br>       break;  <br>                case EventName.TransactionPaid:<br>                    console.log(`Transaction ${eventData.data.id}  paid`);<br>                    /* XXX Create new paid user in redis */<br>                    await redisUserDB.createNewPaidUser(JSON.parse(rawRequestBody));<br>       break;  <br>                case EventName.TransactionUpdated:<br>                    console.log(`Transaction ${eventData.data.id}  updated`);<br>       break;  <br>                default:<br>                    console.log(eventData.eventType);<br>            }<br>        } else {<br>            console.log(&#39;Signature missing in header&#39;);<br>        }<br>    } catch (e) {<br>        console.log(&quot;Signature mismatch in Paddle transaction created webhook&quot;);<br>        console.log(e);<br>        customLogger.error(new Error(e));<br>    }<br>    res.send(&#39;Processed webhook event&#39;);<br>});</pre><p>You have the real meat of the article in these two code blocks but we have a lot of points to discuss.</p><h3>Creating paddle IDs</h3><p>We need only these for now. All are from the dashboard after you login to the paddle sandbox account.</p><ul><li>productId</li><li>priceId</li><li>API key</li><li>client token</li><li>webhook secret(not from dashboard but from API)</li><li>webhook endpoint</li></ul><p>The webhook endpoint is the URL paddle uses for sending webhook.</p><p>I have two products, so I have two productIds and two priceIds.</p><p>This is a sample paddle REST API query.</p><pre># XXX List notifications<br>$ curl \<br>-H &quot;Authorization: Bearer \<br>pdl_sdbx_apikey_01kchw &quot; \<br>https://sandbox-api.paddle.com/notifications|jq|less</pre><p>Response is <a href="https://pastebin.com/GaDZ0FTk">here</a>.</p><h3>What is a webhook?</h3><p>Any experienced programmer knows websockets, callbacks and webhooks.</p><p>When you do a REST API call you are the client and the server is the API endpoint.</p><p>However in the case of webhooks the role is reversed, that is useful for payment processors and asynchronous APIs that take long time to run.</p><p>Paddle payments use webhook to notify us that a payment has been successful.</p><blockquote>Before we proceed we must configure the paddle webhook URL in the Paddle dashboard.</blockquote><p>Using that we can implement our express.js endpoints for verifying paid users.</p><p>In the above code the strange looking IDs are created in the Paddle dashboard for various purposes.</p><p>Full details are beyond scope of this article.</p><p>The paddle API is needed to obtain the paddle-secret-key for webhooks.</p><p>This is the curl command I used followed by manual copy paste of the JSON line.</p><pre>curl \<br> -H &quot;Authorization: Bearer \<br> pdl_sdbx_apikey_01kchpc1_1nmHMP97jYR_Am7 &quot; \<br> https://sandbox-api.paddle.com/notification-settings/ntfset_01kdhb|jq|less</pre><p>Response is this.</p><pre>{<br>  &quot;data&quot;: {<br>    &quot;id&quot;: &quot;ntfset_01kdr0zemvq1g344pmz4snhmhb&quot;,<br>    &quot;description&quot;: &quot;My sandbox webhook&quot;,<br>    &quot;type&quot;: &quot;url&quot;,<br>    &quot;destination&quot;: &quot;https://api.photoveda.pro/paddle/paddle-webhook&quot;,<br>    &quot;active&quot;: true,<br>    &quot;api_version&quot;: 1,<br>    &quot;include_sensitive_fields&quot;: true,<br>    &quot;subscribed_events&quot;: [<br>      {<br>        &quot;name&quot;: &quot;transaction.billed&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction is billed. Its status field changes to billed and billed_at is populated.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.canceled&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction is canceled. Its status field changes to canceled.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.completed&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction is completed. Its status field changes to completed.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction is created.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.paid&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction is paid. Its status field changes to paid.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.past_due&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction becomes past due. Its status field changes to past_due.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.payment_failed&quot;,<br>        &quot;description&quot;: &quot;Occurs when a payment fails for a transaction. The payments array is updated with details of the payment attempt.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.ready&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction is ready to be billed. Its status field changes to ready.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction is updated.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;transaction.revised&quot;,<br>        &quot;description&quot;: &quot;Occurs when a transaction is revised.&quot;,<br>        &quot;group&quot;: &quot;Transaction&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.activated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription becomes active. Its status field changes to active. This means any trial period has elapsed and Paddle has successfully billed the customer.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.canceled&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription is canceled. Its status field changes to canceled.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription is created. subscription.trialing or subscription.activated typically follow.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.imported&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription is imported.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.past_due&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription has an unpaid transaction. Its status changes to past_due.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.paused&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription is paused. Its status field changes to paused.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.resumed&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription is resumed after being paused. Its status field changes to active.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.trialing&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription enters trial period.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;subscription.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a subscription is updated.&quot;,<br>        &quot;group&quot;: &quot;Subscription&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;product.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a product is created.&quot;,<br>        &quot;group&quot;: &quot;Product&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;product.imported&quot;,<br>        &quot;description&quot;: &quot;Occurs when a product is imported.&quot;,<br>        &quot;group&quot;: &quot;Product&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;product.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a product is updated.&quot;,<br>        &quot;group&quot;: &quot;Product&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;price.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a price is created.&quot;,<br>        &quot;group&quot;: &quot;Price&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;price.imported&quot;,<br>        &quot;description&quot;: &quot;Occurs when a price is imported.&quot;,<br>        &quot;group&quot;: &quot;Price&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;price.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a price is updated.&quot;,<br>        &quot;group&quot;: &quot;Price&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;customer.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a customer is created.&quot;,<br>        &quot;group&quot;: &quot;Customer&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;customer.imported&quot;,<br>        &quot;description&quot;: &quot;Occurs when a customer is imported.&quot;,<br>        &quot;group&quot;: &quot;Customer&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;customer.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a customer is updated.&quot;,<br>        &quot;group&quot;: &quot;Customer&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;payment_method.saved&quot;,<br>        &quot;description&quot;: &quot;Occurs when a customer saves a payment method to their account.&quot;,<br>        &quot;group&quot;: &quot;Payment Method&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;payment_method.deleted&quot;,<br>        &quot;description&quot;: &quot;Occurs when a customer removes a payment method from their account.&quot;,<br>        &quot;group&quot;: &quot;Payment Method&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;address.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when an address is created.&quot;,<br>        &quot;group&quot;: &quot;Address&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;address.imported&quot;,<br>        &quot;description&quot;: &quot;Occurs when a address is imported.&quot;,<br>        &quot;group&quot;: &quot;Address&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;address.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when an address is updated.&quot;,<br>        &quot;group&quot;: &quot;Address&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;business.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a business is created.&quot;,<br>        &quot;group&quot;: &quot;Business&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;business.imported&quot;,<br>        &quot;description&quot;: &quot;Occurs when a business is imported.&quot;,<br>        &quot;group&quot;: &quot;Business&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;business.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a business is updated.&quot;,<br>        &quot;group&quot;: &quot;Business&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;adjustment.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when an adjustment is created.&quot;,<br>        &quot;group&quot;: &quot;Adjustment&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;adjustment.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when an adjustment is updated, the only time an adjustment will be updated is when the status changes from pending to approved or from pending to rejected.&quot;,<br>        &quot;group&quot;: &quot;Adjustment&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;payout.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a payout is created.&quot;,<br>        &quot;group&quot;: &quot;Payout&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;payout.paid&quot;,<br>        &quot;description&quot;: &quot;Occurs when a payout is paid.&quot;,<br>        &quot;group&quot;: &quot;Payout&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;discount.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a discount is created.&quot;,<br>        &quot;group&quot;: &quot;Discount&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;discount.imported&quot;,<br>        &quot;description&quot;: &quot;Occurs when a discount is imported.&quot;,<br>        &quot;group&quot;: &quot;Discount&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;discount.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a discount is updated.&quot;,<br>        &quot;group&quot;: &quot;Discount&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;discount_group.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a discount group is created.&quot;,<br>        &quot;group&quot;: &quot;Discount Group&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;discount_group.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a discount group is updated.&quot;,<br>        &quot;group&quot;: &quot;Discount Group&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;report.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a report is created.&quot;,<br>        &quot;group&quot;: &quot;Report&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;report.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a report is updated.&quot;,<br>        &quot;group&quot;: &quot;Report&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;api_key.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when an API key is created.&quot;,<br>        &quot;group&quot;: &quot;API Key&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;api_key.expired&quot;,<br>        &quot;description&quot;: &quot;Occurs when an API key has expired.&quot;,<br>        &quot;group&quot;: &quot;API Key&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;api_key.expiring&quot;,<br>        &quot;description&quot;: &quot;Occurs when an API key is expiring.&quot;,<br>        &quot;group&quot;: &quot;API Key&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;api_key.revoked&quot;,<br>        &quot;description&quot;: &quot;Occurs when an API key is revoked.&quot;,<br>        &quot;group&quot;: &quot;API Key&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;api_key.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when an API key is updated.&quot;,<br>        &quot;group&quot;: &quot;API Key&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;api_key_exposure.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when an API key exposure is created.&quot;,<br>        &quot;group&quot;: &quot;API Key Exposure&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;client_token.created&quot;,<br>        &quot;description&quot;: &quot;Occurs when a client token is created.&quot;,<br>        &quot;group&quot;: &quot;Client Token&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;client_token.updated&quot;,<br>        &quot;description&quot;: &quot;Occurs when a client token is updated.&quot;,<br>        &quot;group&quot;: &quot;Client Token&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      },<br>      {<br>        &quot;name&quot;: &quot;client_token.revoked&quot;,<br>        &quot;description&quot;: &quot;Occurs when a client token is revoked.&quot;,<br>        &quot;group&quot;: &quot;Client Token&quot;,<br>        &quot;available_versions&quot;: [<br>          1<br>        ]<br>      }<br>    ],<br>    &quot;endpoint_secret_key&quot;: &quot;pdl_ntfset_SECRET_KEY&quot;,<br>    &quot;traffic_source&quot;: &quot;platform&quot;<br>  },<br>  &quot;meta&quot;: {<br>    &quot;request_id&quot;: &quot;a72c7d17-84bf-4d8e-af61-2854ca9c5b20&quot;<br>  }<br>}</pre><p>Look at the 7th line from the end. That is our secret key to be used in the webhook.</p><p>We have seen our webhook code already.</p><p>It runs inside an API endpoint and in this case we also do signature verification.</p><h3>Nginx config for webhook</h3><p>I use nginx for my website and webhook runs in express.js on a different port listening on localhost.</p><p>Nginx serves the paddle checkout form and pricing page where paddle checkout occurs.</p><p>We have to translate the webook URL path to our express running on localhost and in our case port 5000.</p><p>How we do this is hereby explained.</p><pre>$ cat /etc/nginx/sites-enabled/default<br>  <br>location /paddle/ {<br>            # Add a trailing slash to proxy_pass to remove the /app1 prefix when forwarding to the backend<br>            proxy_pass http://localhost:5000/;<br>            # Preserve the original Host header and client IP<br>            proxy_set_header Host $host;<br>            proxy_set_header X-Real-IP $remote_addr;<br>            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>            proxy_set_header X-Forwarded-Proto https;<br>        }</pre><p>So now when you send a request to your website URL with the paddle path it gets redirected to our express.js (typically invoked with pm2 for background) on port 5000.</p><p>Now let us get back to our original purpose.</p><p>The idea is that any path after the <strong>paddle</strong> prefix are forwarded to our endpoints in express.</p><h3>Building pricing page for paddle overlay checkout</h3><p>It is just a bunch of HTML, CSS and JS using grid layout.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3751da474e2c84190316bee01168774f/href">https://medium.com/media/3751da474e2c84190316bee01168774f/href</a></iframe><blockquote>The card details for bogus checkout are as follows:</blockquote><blockquote>Card # 4000 0566 5566 5556</blockquote><blockquote>Expiry date 05/30 (any future date)</blockquote><blockquote>Name any</blockquote><blockquote>CVV 100</blockquote><p>Now we are ready to look at the modular code of the express.js webhook.</p><h3>Express.js routes and redis userDB for webhook processing</h3><p>First of all we need to configure a .env file like this.</p><pre>APP_NAME=Webhook (Development)<br>API_URL=http://localhost<br>PORT=5000<br>NODE_ENV=development<br>PADDLE_CLIENT_TOKEN=&quot;test_317b04c2&quot;<br>PADDLE_WEBHOOK_SECRET=&quot;pdl_ntfset_01kdr0ze&quot;</pre><p>This is the most important part of the webhook. Without this all our code will fail.</p><p>Let us look at the entire source starting with package.json.</p><pre>{<br>  &quot;name&quot;: &quot;paddle&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;main&quot;: &quot;paddle-webhook.js&quot;,<br>  &quot;type&quot;: &quot;module&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;node paddle-webhook.js&quot;,<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;@paddle/paddle-node-sdk&quot;: &quot;^3.5.0&quot;,<br>    &quot;cors&quot;: &quot;^2.8.5&quot;,<br>    &quot;dotenv&quot;: &quot;^17.2.3&quot;,<br>    &quot;express&quot;: &quot;^4.21.2&quot;,<br>    &quot;morgan&quot;: &quot;^1.10.1&quot;,<br>    &quot;paddle-billing&quot;: &quot;^3.1.0&quot;,<br>    &quot;redis&quot;: &quot;^5.10.0&quot;<br>  }<br>}</pre><p>Then paddle-webhook.js.</p><pre>import {<br>    Paddle,<br>    EventName,<br>    Environment,<br>    LogLevel,<br>} from &quot;@paddle/paddle-node-sdk&quot;;<br>import cors from &quot;cors&quot;;<br>import {<br>    parseWebhookBody<br>} from &quot;paddle-billing/webhooks&quot;;<br>import express from &#39;express&#39;<br>import morgan from &#39;morgan&#39;;<br>import {<br>    createRequire<br>} from &quot;module&quot;;<br>import dotenv from &#39;dotenv&#39;;<br>import fs from &#39;fs&#39;;<br>import router  from &#39;./userDBRoutes.js&#39;; <br>import redisUserDB from &#39;./redisUserDB.js&#39;;<br><br>const output = fs.createWriteStream(&#39;./logs/payments.json&#39;, {<br>    flags: &#39;a&#39;<br>});<br>const errorOutput = fs.createWriteStream(&#39;./logs/webhook-errors.log&#39;, {<br>    flags: &#39;a&#39;<br>});<br><br>const customLogger = new console.Console(output, errorOutput);<br><br>dotenv.config({<br>    path: &#39;.env&#39;<br>});<br><br>const require = createRequire(import.meta.url);<br>const app = express();<br>app.use(cors({<br>    origin: &#39;*&#39;,<br>    &#39;methods&#39;: &#39;GET,HEAD,PUT,PATCH,POST,DELETE&#39;,<br>}));<br>app.use(function(req, res, next) {<br>    res.header(&#39;Access-Control-Allow-Origin&#39;, req.headers.origin);<br>    res.header(&quot;Access-Control-Allow-Headers&quot;, &quot;Origin, X-Requested-With, Content-Type, Accept&quot;);<br>    next();<br>});<br>app.use(express.raw());<br>app.use(morgan(&#39;dev&#39;));<br><br>require(&quot;dotenv&quot;).config();<br>const token = process.env.PADDLE_CLIENT_TOKEN;<br>const secret = Buffer.from(process.env.PADDLE_WEBHOOK_SECRET);<br><br>const paddle = new Paddle(token, {<br>    eventCallback: function(data) {<br>        console.log(data);<br>    }<br>});<br><br><br>app.post(&#39;/paddle-webhook&#39;, express.raw({<br>    type: &#39;application/json&#39;<br>}), async function(req, res) {<br>    const signature = req.headers[&#39;paddle-signature&#39;] || &#39;&#39;;<br>    // req.body should be of type `buffer`, convert to string before passing it to `unmarshal`. <br>    // If express returned a JSON, remove any other middleware that might have processed raw request to object<br>    const rawRequestBody = req.body.toString();<br>    customLogger.log(JSON.stringify(JSON.parse(rawRequestBody), null, 2));<br><br>    try {<br>        if (signature &amp;&amp; rawRequestBody) {<br>            // Parse the webhook<br>            const webhook = parseWebhookBody(<br>                null,<br>                secret,<br>                signature,<br>                // ⚠️ the body must be raw string to parse!<br>                req.body.toString()<br>            );<br>            // If the webhook is invalid, it will be null<br>            if (!webhook) {<br>                res.status(400).send(&quot;Bad Request&quot;);<br>                return;<br>            }<br>            // The `unmarshal` function will validate the integrity of the webhook and return an entity<br>            const eventData = await paddle.webhooks.unmarshal(rawRequestBody, secret, signature);<br>            switch (eventData.eventType) {<br>                case EventName.ProductUpdated:<br>                    console.log(`Product ${eventData.data.id}  updated`);<br>                    break;<br>                case EventName.SubscriptionUpdated:<br>                    console.log(`Subscription ${eventData.data.id}  updated`);<br>                    break;<br>                case EventName.TransactionCreated:<br>                    console.log(`Transaction ${eventData.data.id}  created`);<br>                    break;<br>                case EventName.TransactionReady:<br>                    console.log(`Transaction ${eventData.data.id}  ready`);<br>                    break;<br>                case EventName.TransactionCompleted:<br>                    console.log(`Transaction ${eventData.data.id}  completed`);<br>       break;  <br>                case EventName.TransactionPaid:<br>                    console.log(`Transaction ${eventData.data.id}  paid`);<br>                    /* XXX Create new paid user in redis */<br>                    await redisUserDB.createNewPaidUser(JSON.parse(rawRequestBody));<br>       break;  <br>                case EventName.TransactionUpdated:<br>                    console.log(`Transaction ${eventData.data.id}  updated`);<br>       break;  <br>                default:<br>                    console.log(eventData.eventType);<br>            }<br>        } else {<br>            console.log(&#39;Signature missing in header&#39;);<br>        }<br>    } catch (e) {<br>        console.log(&quot;Signature mismatch in Paddle transaction created webhook&quot;);<br>        console.log(e);<br>        customLogger.error(new Error(e));<br>    }<br>    res.send(&#39;Processed webhook event&#39;);<br>});<br><br><br><br><br>app.use(&#39;/&#39;, router); <br>const PORT = 5000;<br>app.listen(PORT, () =&gt;<br>    console.log(`Server running at http://localhost:${PORT}`)<br>);</pre><p>Now redisUserDB.js.</p><pre>import {<br>    createClient<br>} from &#39;redis&#39;;<br><br>const redisUserDB = createClient();<br><br>async function initUserDB() {<br>    await redisUserDB.connect();<br>    console.log(&quot;Connected to redis&quot;);<br>}<br><br>initUserDB();<br><br>redisUserDB.fetchAllUsers = async function () {<br>    let results = await redisUserDB.json.get(&#39;user&#39;);<br>    return results;<br>};<br><br>redisUserDB.createNewPaidUser  = async function (txn) {<br>    let pU = {};<br><br>    pU.txnId = txn.data.id;<br>    console.log(txn.data.id);<br>    console.log(txn.event_type);<br><br>    let occurred_at = new Date(txn.occurred_at);<br>    let ts = Date.parse(occurred_at);<br>    let localTime = new Date(ts).toLocaleString();<br>    console.log(txn.occurred_at);<br>    console.log(`Timestamp: ${ts}`);<br>    console.log(`Local time: ${localTime}`);<br><br>    pU.ts = ts;<br>    pU.localTime = localTime;<br>    console.log(txn.data.invoice_number);<br>    console.log(txn.data.customer_id);<br>    pU.invoice_number = txn.data.invoice_number;<br>    pU.customerId = txn.data.customer_id;<br><br>    console.log(txn.data.payments[0].amount);<br>    console.log(txn.data.payments[0].method_details.type);<br>    console.log(txn.data.payments[0].method_details.card.type);<br>    console.log(txn.data.payments[0].method_details.card.last4);<br>    console.log(txn.data.payments[0].method_details.card.cardholder_name);<br>    pU.amount = txn.data.payments[0].amount;<br>    pU.unitPrice = txn.data.items[0].price.unit_price.amount;<br>    pU.paymentType = txn.data.payments[0].method_details.type;<br>    pU.cardType = txn.data.payments[0].method_details.card.type;<br>    pU.cardLast4 = txn.data.payments[0].method_details.card.last4;<br>    pU.cardName = txn.data.payments[0].method_details.card.cardholder_name;<br><br><br>    console.log(txn.data.custom_data.name);<br>    console.log(txn.data.custom_data.plan);<br>    console.log(txn.data.custom_data.email);<br>    console.log(txn.data.custom_data.product);<br>    console.log(txn.data.custom_data.productId);<br><br>    pU.name = txn.data.custom_data.name;<br>    pU.plan = txn.data.custom_data.plan;<br>    pU.email = txn.data.custom_data.email;<br>    pU.product = txn.data.custom_data.product;<br>    pU.productId = txn.data.custom_data.productId;<br><br>    console.log(JSON.stringify(pU, null, 2));<br><br>    console.log(`creating User ${pU.name} , email ${pU.email} <br>  for plan ${pU.plan} for product ${pU.product}`);<br><br>    let userList = await this.fetchAllUsers();<br>    for (let u of userList) {<br>        if (u.email == pU.email) {<br>            return ({<br>                code: 550,<br>                msg: &quot;Error: User exists&quot;,<br>         email: pU.email<br>            });<br>        }<br>    }<br><br>    pU.firstSeen = new Date().getTime();<br>    userList.push(pU);<br>    await redisUserDB.json.set(&#39;user&#39;, &#39;$&#39;, userList);<br>    return ({<br>        code: 200,<br>        msg: &quot;User created&quot;,<br>        email: pU.email<br>    });<br>};<br><br><br>redisUserDB.fetchUser = async function (email) {<br>    let users = await redisUserDB.json.get(&#39;user&#39;);<br><br>    for (let u of users) {<br>        if (u.email == email) {<br>            return u;<br>        }<br>    }<br>    return null;<br>};<br><br>redisUserDB.fetchAllQRUsers = async function () {<br>    let users = await redisUserDB.json.get(&#39;user&#39;);<br>    let QRUsers = [];<br><br>    for (let u of users) {<br>        if (u.product == &#39;QR&#39;) {<br>            QRUsers.push(u);<br>        }<br>    }<br>    return QRUsers;<br>};<br><br>redisUserDB.fetchAllScreenshotUsers = async function () {<br>    let users = await redisUserDB.json.get(&#39;user&#39;);<br>    let ScreenshotUsers = [];<br>    for (let u of users) {<br>        if (u.product == &#39;Screenshot&#39;) {<br>            ScreenshotUsers.push(u);<br>        }<br>    }<br>    return ScreenshotUsers;<br>}<br><br>redisUserDB.delUser  = async function (email) {<br>    let user = await this.fetchUser(email);<br>    if (user) {<br>        let userList = await this.fetchAllUsers();<br>        for (let i = 0; i &lt; userList.length; i++) {<br>            if (userList[i].email == email) {<br>                userList.splice(i, 1);<br>                await redisUserDB.json.set(&#39;user&#39;, &#39;$&#39;, userList);<br>  break;<br>            }<br>        }<br>    }<br>    return ({<br>        code: 200,<br>        msg: &quot;User deleted&quot;,<br>        email: email<br>    });<br>};<br><br>redisUserDB.updatePaidUser = async function (email, args) {<br>    let users = await redisUserDB.json.get(&#39;user&#39;);<br>    for (let u of  users) {<br>        if (u.email == email) {<br>            break;<br>        }<br>    }<br>    let newU = Object.assign({}, result, args)<br>    await redisUserDB.json.set(&#39;user&#39;, &#39;$&#39;, newU);<br>}<br><br><br>export default redisUserDB;</pre><p>Finally all the express.js routes userDBRoutes.js.</p><pre>import express from &#39;express&#39;;<br>import redisUserDB from &#39;./redisUserDB.js&#39;;<br>const router = express.Router();<br><br><br>router.post(&quot;/fetchAllQRUsers&quot;, async (req, res) =&gt; {<br>    res.setHeader(&quot;Content-Type&quot;, &quot;routerlication/javascript&quot;);<br>    let respObj = await redisUserDB.fetchAllQRUsers();<br>    console.log(respObj);<br>    return res.json(respObj);<br>});<br><br>router.post(&quot;/fetchAllScreenshotUsers&quot;, async (req, res) =&gt; {<br>    res.setHeader(&quot;Content-Type&quot;, &quot;routerlication/javascript&quot;);<br>    let respObj = await redisUserDB.fetchAllScreenshotUsers();<br>    console.log(respObj);<br>    return res.json(respObj);<br>});<br><br><br>// Display user statistics<br>router.post(&#39;/showUserStats&#39;,  async function(req, res) {<br>    validateKey(req, res);<br>    if (res.headersSent) return;<br><br>    let respObj = await redisUserDB.fetchUser(req.body.key);<br>    console.log(respObj);<br>    return res.json(respObj);<br>});<br><br><br>// XXX List Users<br>router.post(&#39;/listUsers&#39;,  async function(req, res) {<br>    validateKey(req, res);<br>    if (res.headersSent) return;<br>    let respObj = await redisUserDB.fetchAllUsers();<br>    console.log(respObj);<br>    return res.json(respObj);<br>});<br><br><br>// XXX fetch User<br>router.post(&quot;/fetchUser&quot;, async (req, res) =&gt; {<br>    let email = req.body.email;<br>    console.log(&quot;I got fetchUser with email:: &quot;, email);<br>    let respObj = await redisUserDB.fetchUser(email);<br>    //console.log(respObj);<br>    if(respObj) <br>     return res.json(respObj);<br>     else {<br>    return res.json({<br>        code: 400,<br>        msg: &quot;User not found&quot;<br>    });<br>     }<br>});<br><br>// XXX delUser<br>router.post(&#39;/delUser&#39;,  async function(req, res) {<br><br>    await redisUserDB.delUser(req.body.email);<br>    return res.json({<br>        code: 100,<br>        msg: &quot;User deleted&quot;<br>    });<br>});<br><br>router.post(&#39;/checkUserPaid&#39;, async (req, res) =&gt; {<br>    let {<br>        email<br>    } = req.body;<br>    let respObj = await redisUserDB.fetchUser(email);<br>    if (respObj) {<br>        return res.json({<br>            code: 200,<br>            isPaid: true,<br>            message: &#39;Pro features unlocked&#39;<br>        });<br>    } else {<br>        return res.json({<br>            code: 400,<br>            isPaid: false,<br>            message: &#39;Free version&#39;<br>        });<br>    }<br>});<br>// Handle root URL (&quot;/&quot;) to prevent 404 errors<br>router.get(&quot;/&quot;, (req, res) =&gt; {<br>    res.send(<br>        &quot;Redis paid user JSON db is running! &quot;<br>    );<br>});<br><br>export default router;<br><br></pre><h3>Conclusion</h3><p>Phew that is it!</p><p>Finally after all our efforts we are ready to collect payments for our prized Chrome plugin.</p><p>My user looks like this using redis JSON.</p><pre>$ echo &#39;json.get user $&#39; | redis-cli | jq<br>{                                                                                                                        <br>      &quot;txnId&quot;: &quot;txn_01kdx7c5tdj8ay281ggz5xkcdr&quot;,                                                                             <br>      &quot;ts&quot;: 1767286150000,                                                                                                   <br>      &quot;localTime&quot;: &quot;1/1/2026, 10:19:10 PM&quot;,                                                                                  <br>      &quot;invoice_number&quot;: null,                                                                                                <br>      &quot;customerId&quot;: &quot;ctm_01kdx6gtb7e60bmtyjpejd4r1h&quot;,                                                                        <br>      &quot;amount&quot;: &quot;6962&quot;,                                                                                                      <br>      &quot;unitPrice&quot;: &quot;5900&quot;,    <br>      &quot;paymentType&quot;: &quot;card&quot;,<br>      &quot;cardType&quot;: &quot;visa&quot;,                                     <br>      &quot;cardLast4&quot;: &quot;5556&quot;,                                    <br>      &quot;cardName&quot;: &quot;Tarun Shah&quot;,<br>      &quot;name&quot;: &quot;Drink Now&quot;,    <br>      &quot;plan&quot;: &quot;premium&quot;,      <br>      &quot;email&quot;: &quot;samp@gmail.com&quot;,                              <br>      &quot;product&quot;: &quot;Screenshot lifetime deal&quot;,                  <br>      &quot;productId&quot;: &quot;pro_01kcrmmxy0qpxz2zx12fd6s0p6&quot;,          <br>      &quot;firstSeen&quot;: 1767286151578                              <br>    }              </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ea02f099624" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two examples of tabs without using a single line of JavaScript]]></title>
            <link>https://medium.com/@girish1729/two-examples-of-tabs-without-using-a-single-line-of-javascript-116fb7ad4201?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/116fb7ad4201</guid>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Wed, 31 Dec 2025 03:52:24 GMT</pubDate>
            <atom:updated>2025-12-31T03:52:24.004Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zbjC1OMB6lgVuukz0k3f3A.png" /><figcaption>First tab type</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jqi-VsLDt6vqwUiBQxgQ2g.png" /><figcaption>Second tab type</figcaption></figure><p>I guess I copied the code from some Google search and improved it.</p><p>The tab logic is not mine, it is from some Internet resource.</p><p>However there is value in the fact that I edited it to suit my needs.</p><p>Here is the full source.</p><p>For a long time I confess I thought it impossible to have tabs without JavaScript.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd2f10050549091eb9bcea7b9042ae8b/href">https://medium.com/media/cd2f10050549091eb9bcea7b9042ae8b/href</a></iframe><h3>Conclusion</h3><p>Just doing great stuff without JavaScript is fun.</p><p>In both cases we find we are using the checkbox form element.</p><p>The styling is so completely different though.</p><p>You could have some animation and transform CSS to add some more jazz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=116fb7ad4201" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create image filters with an overlay slider with html,css,js]]></title>
            <link>https://medium.com/@girish1729/create-image-filters-with-an-overlay-slider-with-html-css-js-413349c3e79f?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/413349c3e79f</guid>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Tue, 30 Dec 2025 03:12:22 GMT</pubDate>
            <atom:updated>2025-12-30T03:12:22.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPhJadkT35oWdRUDpYf77Q.png" /><figcaption>Screenshot of image overlay slider</figcaption></figure><p>The story goes like this.</p><p>You have image controls right on top of the image which is hidden in the body.</p><p>But we use some JavaScript to load this into the body background as a cover.</p><p>Then we create a hidden canvas element and perform our filter operations.</p><p>Once we are ready we transfer that canvas imageData into the body background.</p><p>Here is the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cc3bd0f2366a7d4f83a6a1a70670850/href">https://medium.com/media/7cc3bd0f2366a7d4f83a6a1a70670850/href</a></iframe><p>Here is the video.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*YL81U2jcvt4zKCPzytEDTA.gif" /><figcaption>Video of the application</figcaption></figure><h3>Conclusion</h3><p>I changed this code to makek this a button click overlay.</p><p>I this case however have this permanently on background cover on the right side.</p><p>Hope you find this useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=413349c3e79f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Font effects with Google fonts]]></title>
            <link>https://medium.com/@girish1729/font-effects-with-google-fonts-70619af3c709?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/70619af3c709</guid>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Tue, 30 Dec 2025 02:12:22 GMT</pubDate>
            <atom:updated>2025-12-30T02:12:22.906Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iQWDfd06tZffFicnGScE6Q.png" /><figcaption>Google font effects on html5 canvas and html</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ts-kxE__dp2aAefdSKj2Dg.png" /><figcaption>HTML CSS stroke text</figcaption></figure><p>These are some font decorations or fun.</p><p>I am using webfontloader.js for loading Google fonts.</p><p>As the fonts change from the select menu the page is updated with new fonts both on page html and canvas.</p><p>Here are the two gists.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/257815d8cc24d6319bbaf5264941a82b/href">https://medium.com/media/257815d8cc24d6319bbaf5264941a82b/href</a></iframe><p>This one is the stroking of text.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a16c3f6d4d2772f23a510e62bcff316c/href">https://medium.com/media/a16c3f6d4d2772f23a510e62bcff316c/href</a></iframe><h3>Conclusion</h3><p>in order to run these you just have to</p><pre># npm install -g http-server</pre><p>With that installed you can run http-server on any directory where these files are stored and you can access from browser using the URL <a href="http://localhost:8080/">localhost:8080</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70619af3c709" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some interesting grid layouts]]></title>
            <link>https://medium.com/@girish1729/some-interesting-grid-layouts-555cff851ea8?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/555cff851ea8</guid>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Mon, 29 Dec 2025 06:16:42 GMT</pubDate>
            <atom:updated>2025-12-29T06:16:42.049Z</atom:updated>
            <content:encoded><![CDATA[<p>I have this in my code repo and I thought why not dicuss it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*toMjevEs00rLs98SsX1a8A.png" /><figcaption>Simple grid layout for an interesting use case</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60Frtv_YTNjkDOD5gDCALg.png" /><figcaption>I liked this layout</figcaption></figure><p>Here is the code for both.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/611642603fe86a9901e7a577b58db774/href">https://medium.com/media/611642603fe86a9901e7a577b58db774/href</a></iframe><p>Grid layouts are very powerful.</p><p>They come of use in a Chrome plugin or website or any web application.</p><p>Since anything these days is browser driven grid layouts are a very easy way to achieve complex layouts with very little CSS.</p><h3>Conclusion</h3><p>I have many other code samples lying around and we can discuss them in future.</p><p>Newspaper layout and typical multi column layout that is common in websites.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=555cff851ea8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Long running image proc using sharp on Express with HTML image display]]></title>
            <link>https://medium.com/@girish1729/long-running-image-proc-using-sharp-on-express-with-html-image-display-01061d6295e6?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/01061d6295e6</guid>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Mon, 29 Dec 2025 02:08:21 GMT</pubDate>
            <atom:updated>2025-12-29T02:08:21.024Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvyHV_hO7ihdFAkyoxUe0Q.png" /><figcaption>Long running tasks with polling</figcaption></figure><p>It is a very common programming paradigm to have long running APIs which we do a status check by polling in a while loop on client side.</p><p>In our case the client is the browser, but we use setTimeOut() for polling every 400ms.</p><p>On the server side we use sharp image processing library on node.js to convert an input image sent as JSON imageData to greyscale.</p><p>Here is the full code for your perusal.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2697e1f2d9316de7a5140610971ac5cc/href">https://medium.com/media/2697e1f2d9316de7a5140610971ac5cc/href</a></iframe><h3>Conclusion</h3><p>This is just a sample for how we can achieve great things by using polling for long running tasks.</p><p>However we are using setTimeout() on node.js to simulate a long running task.</p><p>On a real task this will be replaced with production code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01061d6295e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Websockets for status updates using HTML progress element with REST API backend]]></title>
            <link>https://medium.com/@girish1729/websockets-for-status-updates-using-html-progress-element-with-rest-api-backend-cec6675fa91d?source=rss-1db55faeafb0------2</link>
            <guid isPermaLink="false">https://medium.com/p/cec6675fa91d</guid>
            <dc:creator><![CDATA[Girish Venkatachalam]]></dc:creator>
            <pubDate>Sat, 27 Dec 2025 16:15:37 GMT</pubDate>
            <atom:updated>2025-12-27T16:15:37.654Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKkkF6g3kIkmJVbCUwPUvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vJWuVdixlAytjBYZgClfzg.gif" /></figure><p>You can see how the REST API request for a job sends status updates using websockets and how the browser shows the progress in a neat progress bar.</p><p>The implementation of the server side is easy, just some simulation of a long job with setInterval() and websockets for updates.</p><p>On the client side we use HTML and websockets URL with jobID as the URL encoded parameter.</p><p>If you fail to use websockets then the status URL of the REST API job submit response a 202 HTTP status code needs to be queried periodically using polling.</p><p>This involves a lot of work for the programmer too lazy for such heavy work.</p><p>Websockets solves this problem elegantly.</p><p>The only trouble with all this code is that the server side does not use BullMQ, redis and workers like <a href="https://medium.com/@girish1729/bullmq-redis-with-express-js-simple-demo-6b1f63ebdadf">we saw yesterday</a>.</p><p>I need to get that integrated with this code ASAP.</p><p>Enough talk, here is the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dd5a00da29cdad5e882e69a86ba3d68/href">https://medium.com/media/9dd5a00da29cdad5e882e69a86ba3d68/href</a></iframe><h3>Conclusion</h3><p>Though code is a bit chatty the overall logic and flow is pretty straight forward.</p><p>Next in this series is the BullMQ integration to finish this API implementation for long running tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cec6675fa91d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>