<?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 Akash (codeguyakash) on Medium]]></title>
        <description><![CDATA[Stories by Akash (codeguyakash) on Medium]]></description>
        <link>https://medium.com/@codeguyakash?source=rss-cda2c3b22edf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5dvHvKsQg_ciIXlGtBws7g.png</url>
            <title>Stories by Akash (codeguyakash) on Medium</title>
            <link>https://medium.com/@codeguyakash?source=rss-cda2c3b22edf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 25 May 2026 14:29:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codeguyakash/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[Securely encrypting data in a Chrome Extension without sending it to a server (key management…]]></title>
            <link>https://codeguyakash.medium.com/securely-encrypting-data-in-a-chrome-extension-without-sending-it-to-a-server-key-management-e53b78fd865b?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/e53b78fd865b</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[google-chrome-developers]]></category>
            <category><![CDATA[google-chrome]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Wed, 04 Mar 2026 10:40:49 GMT</pubDate>
            <atom:updated>2026-03-10T05:39:19.021Z</atom:updated>
            <content:encoded><![CDATA[<h3>Securely encrypting data in a Chrome Extension without sending it to a server (key management problem) ??</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkymzxFpYFQTVj782WP4oA.png" /></figure><p>I am building a Chrome extension where some user data (for example tab metadata or browsing-related information) must remain on the user’s device due to Chrome Web Store privacy policies. The extension is not allowed to send this data to my server.</p><p>Because of this restriction, I need to store the data locally using something like <a href="http://chrome.storage/">chrome.storage</a> or IndexedDB. However, storing the data in plain text is not acceptable from a security perspective.</p><p>My current approach is to <strong>encrypt the data before storing it locally and decrypt it when needed</strong>.</p><p>For encryption I am using the <strong>Web Crypto API with AES-GCM</strong>, and deriving the key from a user password using <strong>PBKDF2</strong>.</p><p>Here is a simplified version of the encryption logic I am currently using:</p><pre>const ALGO = &#39;AES-GCM&#39;;<br>const KEY_LENGTH = 256;<br>const IV_LENGTH = 12;<br><br><br>export async function deriveKey(password, salt) {<br>  const enc = new TextEncoder();<br>  const keyMaterial = await crypto.subtle.importKey(<br>    &#39;raw&#39;,<br>    enc.encode(password),<br>    &#39;PBKDF2&#39;,<br>    false,<br>    [&#39;deriveKey&#39;]<br>  );<br>  return crypto.subtle.deriveKey(<br>    {<br>      name: &#39;PBKDF2&#39;,<br>      salt,<br>      iterations: 100000,<br>      hash: &#39;SHA-256&#39;<br>    },<br>    keyMaterial,<br>    {<br>      name: ALGO,<br>      length: KEY_LENGTH<br>    },<br>    false,<br>    [&#39;encrypt&#39;, &#39;decrypt&#39;]<br>  );<br>}<br>export async function encryptData(data, masterPassword) {<br>  const enc = new TextEncoder();<br>  const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH));<br>  const salt = crypto.getRandomValues(new Uint8Array(16));<br>  const key = await deriveKey(masterPassword, salt);<br>  const encryptedBuffer = await crypto.subtle.encrypt(<br>    { name: ALGO, iv },<br>    key,<br>    enc.encode(JSON.stringify(data))<br>  );<br>  return {<br>    cipher: bufferToBase64(encryptedBuffer),<br>    iv: bufferToBase64(iv),<br>    salt: bufferToBase64(salt)<br>  };<br>}<br>export async function decryptData(encryptedPayload, masterPassword) {<br>  const { cipher, iv, salt } = encryptedPayload;<br>  const key = await deriveKey(masterPassword, base64ToBuffer(salt));<br>  const decryptedBuffer = await crypto.subtle.decrypt(<br>    { name: ALGO, iv: base64ToBuffer(iv) },<br>    key,<br>    base64ToBuffer(cipher)<br>  );<br>  const dec = new TextDecoder();<br>  return JSON.parse(dec.decode(decryptedBuffer));<br>}<br>function bufferToBase64(buffer) {<br>  return btoa(String.fromCharCode(...new Uint8Array(buffer)));<br>}<br>function base64ToBuffer(base64) {<br>  return Uint8Array.from(atob(base64), c =&gt; c.charCodeAt(0));<br>}<br><br>const password = &#39;1234&#39;;<br>const encrypted = await encryptData(plainTab, password);</pre><p>My main concern is <strong>key management</strong>.</p><p>Since this is a browser extension without a backend, I cannot store a secret key on a server. At the same time, if a key is hardcoded or stored directly in the extension code, it can be extracted by inspecting the extension.</p><p>So my questions are:</p><ol><li>What is the recommended approach for encrypting sensitive data locally in a Chrome extension?</li><li>How should the encryption key be generated and managed securely if everything runs on the client side?</li><li>Is deriving the key from a user-provided master password (using PBKDF2 or similar) considered a good practice in this scenario?</li><li>Are there established patterns used by password managers or other privacy-focused extensions for this problem?</li></ol><p>I am trying to design something similar to how <strong>password managers encrypt vault data locally before storing it</strong>.</p><p><strong>Environment:</strong></p><ul><li>Chrome Extension (Manifest V3)</li><li>JavaScript</li><li>Web Crypto API</li><li>Storage via chrome.storage or IndexedDB</li></ul><p>Have you solved a similar problem in a Chrome extension or another client-only application? If you have any ideas, better approaches, or security recommendations, please leave a reply or reach out to me via email codeguyakash@gmail.com.</p><p>I’d love to learn from your experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e53b78fd865b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Right Way to Install Docker on Ubuntu (No Conflicts, No Headaches)]]></title>
            <link>https://codeguyakash.medium.com/the-right-way-to-install-docker-on-ubuntu-no-conflicts-no-headaches-909615c55c33?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/909615c55c33</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sofware-engineering]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Tue, 24 Feb 2026 12:02:33 GMT</pubDate>
            <atom:updated>2026-02-24T12:02:33.383Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CgyfeoSsSDL7PwzmFQzvnA.png" /></figure><p>If you’re working with Docker on Ubuntu, you might run into issues caused by <strong>old or conflicting Docker packages</strong> such as docker.io, docker-compose, or containerd.</p><p>The best solution is to <strong>completely remove old Docker installations</strong> and then install Docker using the <strong>official Docker repository</strong>.</p><p>In this guide, I’ll walk you through a <strong>clean and reliable way</strong> to remove Docker and reinstall the <strong>latest stable version</strong> on Ubuntu.</p><h3>Step 1: Remove Old Docker Packages (Clean Slate)</h3><p>Ubuntu often installs Docker from its default repository, which can be outdated.</p><p>First, we remove all existing Docker-related packages to avoid conflicts.</p><pre>sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)</pre><p>This command:</p><ul><li>Detects installed Docker-related packages</li><li>Removes them safely</li><li>Ensures there are no leftover conflicting components</li></ul><p>👉 This step is important for a <strong>fresh and stable Docker setup</strong>.</p><h3>Step 2: Update System and Install Required Dependencies</h3><p>Before adding Docker’s official repository, update your system and install required tools:</p><pre>sudo apt update<br>sudo apt install ca-certificates curl</pre><p>These packages allow Ubuntu to:</p><ul><li>Securely download files over HTTPS</li><li>Verify Docker’s authenticity</li></ul><h3>Step 3: Add Docker’s Official GPG Key</h3><p>Docker signs its packages for security.</p><p>We add Docker’s official GPG key so Ubuntu can trust the packages.</p><pre>sudo install -m 0755 -d /etc/apt/keyrings<br>sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc<br>sudo chmod a+r /etc/apt/keyrings/docker.asc</pre><p>This ensures:</p><ul><li>Package integrity</li><li>Secure installation from Docker’s servers</li></ul><h3>Step 4: Add Docker’s Official Repository</h3><p>Now we tell Ubuntu <strong>where to download Docker from</strong>.</p><pre>sudo tee /etc/apt/sources.list.d/docker.sources &lt;&lt;EOF<br>Types: deb<br>URIs: https://download.docker.com/linux/ubuntu<br>Suites: $(. /etc/os-release &amp;&amp; echo &quot;${UBUNTU_CODENAME:-$VERSION_CODENAME}&quot;)<br>Components: stable<br>Signed-By: /etc/apt/keyrings/docker.asc<br>EOF</pre><p>Then refresh the package list:</p><pre>sudo apt update</pre><p>This ensures Ubuntu can now fetch the <strong>latest Docker versions</strong>.</p><h3>Step 5: Install Latest Docker Packages</h3><p>Install Docker and its essential components:</p><pre>sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin</pre><p>This installs:</p><ul><li>Docker Engine</li><li>Docker CLI</li><li>Container runtime</li><li>Buildx for advanced builds</li><li>Docker Compose v2 (recommended)</li></ul><h3>Step 6: Start and Verify Docker Service</h3><p>Check Docker’s status:</p><pre>sudo systemctl status docker</pre><p>If it’s not running, start it manually:</p><pre>sudo systemctl start docker</pre><p>To verify installation:</p><pre>docker --version<br>docker compose version</pre><p>🎉 If versions show correctly, Docker is installed successfully.</p><h3>Why This Method Is Recommended</h3><ul><li>✅ Avoids outdated Ubuntu packages</li><li>✅ Prevents version conflicts</li><li>✅ Uses Docker’s official repository</li><li>✅ Stable for production &amp; CI/CD setups</li></ul><p>This approach is ideal for:</p><ul><li>Backend developers</li><li>DevOps engineers</li><li>AWS EC2 / VPS servers</li><li>Docker-based production environments</li></ul><p>Ref : <a href="https://docs.docker.com/engine/install/ubuntu/">https://docs.docker.com/engine/install/ubuntu</a></p><p><a href="https://medium.com/u/cda2c3b22edf">Akash (codeguyakash)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=909615c55c33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Deploy a Node.js Backend on AWS EC2 Using Automated GitHub Actions CI/CD]]></title>
            <link>https://codeguyakash.medium.com/deploy-a-node-js-backend-on-aws-ec2-using-automated-github-actions-ci-cd-4a00e07cd389?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a00e07cd389</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Mon, 17 Nov 2025 21:33:49 GMT</pubDate>
            <atom:updated>2026-01-26T13:35:54.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o9pua7TYv1zRdp5g5qTR1A.png" /></figure><p>If you want to deploy your Node.js backend on an EC2 instance <strong>with a fully automated CI/CD pipeline using GitHub Actions</strong>, this guide is for you.<br> We’ll configure EC2, install Node.js via <strong>NodeSource</strong>, setup Nginx as a reverse proxy, use PM2 for process management, and automate everything through GitHub Actions.</p><p>Let’s build a production-grade deployment pipeline!</p><h4>✅ Prerequisites</h4><ul><li>AWS EC2 instance (Ubuntu 22.04 recommended)</li><li>Security groups opened for:</li><li><strong>22 (SSH)</strong></li><li><strong>80 (HTTP)</strong></li><li>GitHub repository containing your Node.js backend</li><li>Your SSH private key for deployment</li></ul><h4>◦ Step 1: Update Your EC2 Instance</h4><p>SSH into your instance and update the packages:</p><pre>sudo apt update &amp;&amp; sudo apt upgrade -y</pre><h4>◦ Step 2: Install Node.js (Using NodeSource — Recommended)</h4><p>We are <strong>not</strong> using the n module.<br> Install the official Node.js 20 LTS with NodeSource:</p><pre>curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -<br>sudo apt install -y nodejs</pre><p>Verify installation:</p><pre>node -v<br>npm -v</pre><h4>◦ Step 3: Install and Configure Nginx</h4><pre>sudo apt install nginx -y<br><br>sudo systemctl start nginx<br>sudo systemctl enable nginx<br>sudo systemctl status nginx</pre><p>Nginx will serve as a <strong>reverse proxy</strong> forwarding port 80 → your Node.js app on port 8000.</p><h4>◦ Step 4: Create Deployment Directory</h4><pre>sudo mkdir -p /var/www/express-app<br>cd /var/www/express-app</pre><p><em>(Optional)</em> Give ownership to ubuntu:</p><pre>sudo chown -R ubuntu:ubuntu /var/www/express-app</pre><h4>◦ Step 5: Configure Nginx Reverse Proxy</h4><p>Create a config file:</p><pre>sudo nano /etc/nginx/sites-available/express-app</pre><p>Paste this:</p><pre>server {<br>    listen 80;<br>    server_name YOUR_EC2_PUBLIC_IP;location / {<br>        proxy_pass http://localhost:8000;<br>        proxy_http_version 1.1;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header Connection &#39;upgrade&#39;;<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 $scheme;<br>        proxy_cache_bypass $http_upgrade;<br>        proxy_connect_timeout 60s;<br>        proxy_send_timeout 60s;<br>        proxy_read_timeout 60s;<br>    }<br>}</pre><p>Enable the config:</p><pre>sudo ln -s /etc/nginx/sites-available/express-app /etc/nginx/sites-enabled/<br>sudo rm /etc/nginx/sites-enabled/default<br>sudo nginx -t<br>sudo systemctl restart nginx</pre><h4>◦ Step 6: Install PM2 to Manage the App</h4><pre>sudo npm install -g pm2<br><br>pm2 startup</pre><p>Your app will later be started via PM2 inside the GitHub Action script.</p><h4>◦ Step 7: Add GitHub Secrets</h4><p>In your GitHub repo:</p><p><strong>Settings → Secrets and variables → Actions → New repository secret</strong></p><p>Add these:</p><ul><li>EC2_HOST → your EC2 Public IP</li><li>EC2_USERNAME → ubuntu</li><li>EC2_SSH_KEY → paste entire .pem key</li></ul><p>Example:</p><pre>-----BEGIN RSA PRIVATE KEY-----<br>...<br>-----END RSA PRIVATE KEY-----</pre><h4>◦ Step 8: Create GitHub Actions Workflow</h4><p>Create:</p><pre>.github/workflows/deploy.yml</pre><p>Paste the following workflow (updated with NodeSource version, no “n”):</p><pre>name: Deploy to EC2<br><br>on:<br>  push:<br>    branches: [main]<br>  workflow_dispatch:<br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - name: Setup Node.js<br>        uses: actions/setup-node@v4<br>        with:<br>          node-version: &quot;20&quot;<br>      - name: Install dependencies<br>        run: npm ci<br>      - name: Build TypeScript<br>        run: npm run build<br>      - name: Create deployment package<br>        run: |<br>          mkdir -p deploy<br>          cp -r dist deploy/<br>          cp -r src deploy/<br>          cp package*.json deploy/<br>          cp ecosystem.config.cjs deploy/<br>          [ -f .env.example ] &amp;&amp; cp .env.example deploy/<br>          tar -czf deploy.tar.gz -C deploy .<br>      - uses: actions/upload-artifact@v4<br>        with:<br>          name: deployment-package<br>          path: deploy.tar.gz<br>          retention-days: 1<br>  deploy:<br>    needs: build<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/download-artifact@v4<br>        with:<br>          name: deployment-package<br>      - name: Deploy to EC2<br>        env:<br>          EC2_HOST: ${{ secrets.EC2_HOST }}<br>          EC2_USERNAME: ${{ secrets.EC2_USERNAME }}<br>          SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }}<br>        run: |<br>          echo &quot;$SSH_PRIVATE_KEY&quot; &gt; private_key.pem<br>          chmod 600 private_key.pem<br>          scp -i private_key.pem -o StrictHostKeyChecking=no deploy.tar.gz ${EC2_USERNAME}@${EC2_HOST}:/tmp/<br>          ssh -i private_key.pem -o StrictHostKeyChecking=no ${EC2_USERNAME}@${EC2_HOST} &lt;&lt; &#39;EOF&#39;<br>            cd /var/www/express-app<br>            sudo chown -R $USER:$USER /var/www/express-app<br>            if [ -d &quot;dist&quot; ]; then<br>              timestamp=$(date +%Y%m%d_%H%M%S)<br>              mkdir -p backups<br>              tar -czf backups/backup_${timestamp}.tar.gz dist package.json ecosystem.config.cjs .env 2&gt;/dev/null || true<br>              ls -t backups/backup_*.tar.gz 2&gt;/dev/null | tail -n +6 | xargs -r rm<br>            fi<br>            tar --overwrite -xzf /tmp/deploy.tar.gz -C /var/www/express-app<br>            rm /tmp/deploy.tar.gz<br>            sudo chown -R $USER:$USER /var/www/express-app<br>            npm ci --omit=dev<br>            if [ ! -f .env ]; then<br>              echo &quot;NODE_ENV=production&quot; &gt; .env<br>              echo &quot;PORT=8000&quot; &gt;&gt; .env<br>            fi<br>            mkdir -p logs<br>            if pm2 describe express-app &gt; /dev/null 2&gt;&amp;1; then<br>              pm2 reload ecosystem.config.cjs --update-env<br>            else<br>              pm2 start ecosystem.config.cjs<br>            fi<br>            pm2 save<br>          EOF<br>          rm private_key.pem<br>      - name: Verify Deployment<br>        env:<br>          EC2_HOST: ${{ secrets.EC2_HOST }}<br>        run: |<br>          sleep 10<br>          response=$(curl -s -o /dev/null -w &quot;%{http_code}&quot; http://${EC2_HOST})<br>          echo &quot;App responded with: $response&quot;</pre><h4>🚀 Your CI/CD Pipeline Is Now Ready!</h4><p>Every time you push to the <strong>main</strong> branch:</p><ol><li>GitHub builds the app</li><li>Packages it</li><li>Uploads to EC2</li><li>Auto-extracts &amp; restarts with PM2</li><li>Nginx serves traffic</li></ol><p><a href="https://codeguyakash.medium.com/how-to-install-node-js-deploy-a-react-vite-app-with-nginx-and-use-pm2-on-ubuntu-fd348374511e">How to Install Node.js, Deploy a React-Vite App with Nginx, and Use PM2 on Ubuntu</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a00e07cd389" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ The Ultimate Guide to GitHub CLI (gh): Supercharge Your GitHub Workflow from the Terminal]]></title>
            <link>https://codeguyakash.medium.com/the-ultimate-guide-to-github-cli-gh-supercharge-your-github-workflow-from-the-terminal-cac301dc3555?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/cac301dc3555</guid>
            <category><![CDATA[cli]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[gh]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Fri, 14 Nov 2025 13:17:50 GMT</pubDate>
            <atom:updated>2025-11-14T13:17:50.985Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re a developer who loves working fast and hates switching windows, <strong>GitHub CLI (gh)</strong> is your secret weapon. Instead of jumping between browser tabs, dashboards, and Git tools, gh brings the full GitHub experience directly into your terminal.</p><p>From creating repositories to managing issues, pull requests, releases, and even gists — GitHub CLI makes your workflow smoother, faster, and far more efficient.</p><p>In this guide, I’ll cover the most essential gh commands you’ll use daily, with clear examples for every feature. Bookmark this article — this will become your GitHub CLI cheat sheet! 💻⚡</p><h3>⭐ What Is GitHub CLI?</h3><p>GitHub CLI (gh) is an official command-line tool that lets you interact with GitHub without opening the browser. You can manage:</p><p>✔️ Repositories</p><p>✔️ Pull Requests</p><p>✔️ Issues</p><p>✔️ Releases</p><p>✔️ Gists</p><p>✔️ Extensions</p><p>✔️ Configuration</p><p>All directly from your command line.</p><h3>🏗️ Repository Management with</h3><h3>gh repo</h3><p>Creating and managing GitHub repositories is effortless with gh repo.</p><h3>Create a new repository</h3><pre>gh repo create my-project --public --clone</pre><h3>Clone a repository</h3><pre>gh repo clone cli/cli</pre><h3>List your repositories</h3><pre>gh repo list --visibility public -L 50</pre><h3>View repository details</h3><pre>gh repo view OWNER/REPO --web</pre><h3>🔀 Pull Request Management with</h3><h3>gh pr</h3><p>Manage pull requests like a pro — without even opening GitHub.</p><h3>Create a pull request</h3><pre>gh pr create --title &quot;Fix: Bug&quot; --body &quot;Fixed the issue&quot;</pre><h3>List pull requests</h3><pre>gh pr list --state closed --author &quot;@me&quot;</pre><h3>Checkout a PR locally</h3><pre>gh pr checkout 32</pre><h3>Merge a PR</h3><pre>gh pr merge --squash --delete-branch</pre><h3>🐞 Issue Management with</h3><h3>gh issue</h3><p>Creating and managing issues becomes super straightforward.</p><h3>Create a new issue</h3><pre>gh issue create --title &quot;Found a bug&quot; --label &quot;bug,help wanted&quot;</pre><h3>List issues</h3><pre>gh issue list --assignee &quot;@me&quot;</pre><h3>View an issue</h3><pre>gh issue view 123 --web</pre><h3>✨ Gist Management with</h3><h3>gh gist</h3><p>Need to share code snippets? Gists are perfect.</p><h3>Create a new gist</h3><pre>gh gist create --public hello.py</pre><h3>List your gists</h3><pre>gh gist list --secret</pre><h3>Clone a gist</h3><pre>gh gist clone 5b0e0062eb8e9654adad7bb1d81cc75f</pre><h3>📦 Release Management with</h3><h3>gh release</h3><p>Automate release workflows from your terminal.</p><h3>Create a release</h3><pre>gh release create v1.2.3 --notes &quot;bugfix release&quot;</pre><h3>Download release assets</h3><pre>gh release download --pattern &#39;*.deb&#39;</pre><h3>List releases</h3><pre>gh release list --limit 10</pre><h3>⚙️ Configuration Management with</h3><h3>gh config</h3><p>Tweak your GitHub CLI environment exactly how you like it.</p><h3>View config</h3><pre>gh config list</pre><h3>Get a specific key</h3><pre>gh config get editor</pre><h3>Set a config key</h3><pre>gh config set git_protocol ssh</pre><h3>Clear cache</h3><pre>gh config clear-cache</pre><h3>🧩 Create Aliases with</h3><h3>gh alias</h3><p>Aliases help you shorten long commands.</p><h3>Create an alias</h3><pre>gh alias set pv &#39;pr view&#39;</pre><h3>List aliases</h3><pre>gh alias list</pre><h3>🛠️ GH Extensions (gh extension)</h3><p>Extensions turn GitHub CLI into a powerful plugin-based tool.</p><h3>Install an extension</h3><pre>gh extension install owner/gh-extension</pre><h3>List extensions</h3><pre>gh extension list</pre><h3>Search for new extensions</h3><pre>gh extension search branch</pre><h3>🔧 Useful Flags You Should Know</h3><h3>Output JSON</h3><pre>gh pr list --json number,title</pre><h3>Template format</h3><pre>gh issue list --template &#39;{{.title}}&#39;</pre><h3>Use a specific repo</h3><pre>gh pr list -R cli/cli</pre><h3>Open in browser</h3><pre>gh pr view 123 -w</pre><h3>Use GH_TOKEN in scripts</h3><pre>export GH_TOKEN=your_token_here</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cac301dc3555" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Your Free Hosting from Sleeping — Meet keepalive-server]]></title>
            <link>https://codeguyakash.medium.com/stop-your-free-hosting-from-sleeping-meet-keepalive-server-764c1dce11d4?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/764c1dce11d4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[npm-package]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Fri, 15 Aug 2025 07:07:03 GMT</pubDate>
            <atom:updated>2025-08-15T07:07:03.177Z</atom:updated>
            <content:encoded><![CDATA[<h3>Stop Your Free Hosting from Sleeping — Meet keepalive-server</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vjTtVOH-Qaj4_gudla7UoA.webp" /></figure><p>If you’ve ever deployed a project on a <strong>free hosting service</strong> like Render, Vercel, Railway, or Glitch, you might have experienced this annoying problem:</p><p>You leave your app running… and after some time, with no incoming requests, <strong>the server goes to sleep</strong>.</p><p>That means the next time someone visits, they face a <strong>cold start</strong> — extra load time while the service spins up your app again.</p><p>For students, hobbyists, or anyone running small side projects, this can make your project feel <strong>slow and unreliable</strong>.</p><h3>The Problem with Free Deployments</h3><p>Free hosting services do this for a reason — to save resources. But for apps that need to stay alive (like API backends, demo projects, or Telegram/Discord bots), <strong>this “sleep mode” can break the experience</strong>.</p><p>For example:</p><ul><li>A bot missing messages because the server was asleep</li><li>Your portfolio API being slow during a job interview</li><li>Class projects failing during a live demo</li></ul><h3>The Solution: Keep Pinging Your Server</h3><p>The idea is simple: <strong>send a request to your own server at fixed intervals</strong> so the hosting provider thinks it’s “in use” and doesn’t put it to sleep.</p><p>That’s exactly what my npm package <a href="https://www.npmjs.com/package/keepalive-server"><strong>keepalive-server</strong></a> does.</p><h3>How keepalive-server Works</h3><p>It’s a <strong>tiny Node.js library</strong> that pings any URL you specify at a fixed interval.</p><p>You can use it to:</p><ul><li>Keep your backend awake</li><li>Ping a /health or /ping endpoint</li><li>Run from a different server or even from the same one</li></ul><h3>Installation</h3><pre>npm i keepalive-server</pre><h3>Usage</h3><h4>ESM</h4><pre>import { ping } from &#39;keepalive-server&#39;;</pre><pre>ping(60000, &#39;https://your-url.com&#39;); // ping every 60 seconds</pre><h4>CommonJS (dynamic import)</h4><pre>(async () =&gt; {<br>  const { ping } = await import(&#39;keepalive-server&#39;);<br>  ping(60000, &#39;https://your-url.com&#39;);<br>})();</pre><h3>API</h3><pre>ping(intervalMs, url, timeoutMs?)</pre><ul><li><strong>intervalMs</strong> → Ping interval in milliseconds (e.g., 60000 for 1 minute)</li><li><strong>url</strong> → Target URL to ping</li><li><strong>timeoutMs</strong> <em>(optional)</em> → Timeout per request (default: 10 seconds)</li></ul><p>💡 Tip: Always ping a <strong>lightweight endpoint</strong> like /health instead of your main API.</p><h3>Why Use This?</h3><ul><li>Keeps your app <strong>responsive</strong> for visitors</li><li><strong>Lightweight</strong> — no heavy dependencies</li><li>Works with <strong>Render, Vercel, Railway, Glitch</strong>, and similar platforms</li><li>Simple enough to add in <strong>two lines of code</strong></li></ul><h3>Final Thoughts</h3><p>If your student project, side hustle, or demo keeps going to sleep, give <a href="https://www.npmjs.com/package/keepalive-server">keepalive-server</a> a try.</p><p>It’s minimal, does exactly one job, and saves you from the embarrassment of saying</p><blockquote><em>“Sorry, it’s loading because my server was asleep…”</em></blockquote><p>You can check out the package here:<br> 👉 <a href="https://www.npmjs.com/package/keepalive-server"><strong>https://www.npmjs.com/package/keepalive-server</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=764c1dce11d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ CORS Error: Jab Browser Siren Bajata Hai aur Developer Jugaad Lagata Hai]]></title>
            <link>https://codeguyakash.medium.com/cors-error-jab-browser-siren-bajata-hai-aur-developer-jugaad-lagata-hai-80c3b8b6e2b1?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/80c3b8b6e2b1</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[cross-origin-resource]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[cors]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Tue, 20 May 2025 08:45:54 GMT</pubDate>
            <atom:updated>2025-05-20T08:48:08.674Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i-OWKCjTauNRJ_FRrg5cgQ.png" /></figure><h3>Ghar ka Smart Sensor</h3><p>Maan lo aapke ghar ke gate par ek <strong>smart sensor</strong> laga hai.<br>Is sensor ko pata hai kaun-kaun <strong>ghar ke asli members</strong> hain: mummy, papa, bhai, didi sab registered.</p><p>Ab ek din aapka dost <em>Raju</em> ghar pe kuch dene aata hai.</p><p>Sensor dekhta hai aur chillata hai:</p><blockquote><strong><em>“Yeh to koi outsider hai!”</em></strong></blockquote><p>Aur phir bajta hai <strong>Teeeeeennnnnnnnnn!!!</strong><br>Ghar ke andar siren baje jaa raha hai.<br>Raju bhi shock mein… ghar wale bhi.</p><blockquote><em>Yahi browser karta hai jab </em><strong><em>CORS error</em></strong><em> deta hai 😂</em></blockquote><h3>🧠 Samjho CORS Kya Hai?</h3><p><strong>CORS = Cross-Origin Resource Sharing</strong></p><p>Yeh browser ka ek security rule hai. Jab aapki frontend app (e.g., localhost:5500) kisi <strong>different origin</strong> ke backend se data maangti hai (e.g., localhost:3000), tab browser kehta hai:</p><blockquote><em>“Bhai, main server se poochunga pehle — tu authorized hai ya nahi!”</em></blockquote><p>Agar server ne <strong>“haan bhai allow hai”</strong> waala header nahi diya, toh browser seedha error de deta hai.</p><h3>🔥 Error Kaise Dikhta Hai?</h3><pre>Access to fetch at &#39;http://localhost:3000/api/data&#39; from origin &#39;http://localhost:5500&#39; has been blocked by CORS policy</pre><p>Developer ka reaction:</p><blockquote><em>“Yaar backend toh chal raha hai! Ye kya natak hai?”</em></blockquote><h3>😎 Jugaadu Developer ka Hack: Extension Lagao</h3><p>Jab developer ke paas server ka control nahi hota ya time nahi hota, toh wo extension install karta hai:</p><blockquote><strong><em>CORS Unblocker</em></strong><em><br> Ya koi custom Chrome extension</em></blockquote><p>Extension browser ko bolta hai:</p><blockquote><em>“Relax bhai, headers toh main add kar raha hoon. Sab set hai.”</em></blockquote><p>Browser bolta hai:</p><blockquote><em>“Oh okay! Mujhe kya, headers mil gaye. Allow kar deta hoon.”</em></blockquote><p>😎 Developer:</p><blockquote><em>“CORS error gaya tel lene.”</em></blockquote><h3>😂 Desi Analogy #2: School Wala Scene</h3><p>Socho school ka gatekeeper ho.<br>Sab students ID card ke saath aate hain.<br>Ek naya ladka bina ID ke aata hai.<br>Gatekeeper chillata hai: <strong>“Kaun hai tu bhai?”</strong> → CORS error.</p><p>Agar uske paas <strong>fake ID card</strong> hota (extension), toh woh andar aa jaata 😅</p><h3>✅ Real Solution (For Developers)</h3><p>CORS ka <strong>sahi tareeka</strong> hai:<br><strong>Server ko batana hota hai ki kaun origin allowed hai.</strong></p><p>Aapko frontend ya backend dono me thoda kaam karna padega:</p><h3>🔧 Option 1: Server Side (Backend Pe Fix)</h3><p>Agar aap backend developer ho (Node.js + Express):</p><pre>const cors = require(&#39;cors&#39;);<br>app.use(cors()); // This allows all origins</pre><pre>// Or specific origin allow:<br>app.use(cors({<br>  origin: &#39;http://localhost:5500&#39;<br>}));</pre><p>Agar aap PHP/Python/Django pe ho, toh bhi response headers me ye bhejna hoga:</p><pre>Access-Control-Allow-Origin: http://localhost:5500<br>Access-Control-Allow-Methods: GET, POST, PUT, DELETE<br>Access-Control-Allow-Headers: Content-Type</pre><h3>🎯 Option 2: Frontend Pe kuch nahi karna padta (bas wait karo!)</h3><p>CORS ka pura control server ke paas hota hai.<br>Frontend se sirf request jaata hai, aur browser verify karta hai server ne allow kiya ya nahi.</p><h3>🔁 Alternate Temporary Fix: Extension</h3><p>Agar aapke paas <strong>server ka access nahi hai</strong>, ya aap just <strong>testing kar rahe ho</strong>, toh:</p><p>✅ Use this Chrome Extension:<br> 🔗 <a href="https://chromewebstore.google.com/search/cors">Allow CORS: Access-Control-Allow-Origin</a></p><p>Ya aap <strong>apna khud ka extension</strong> bhi bana sakte ho (jaise humne upar banaya):</p><ul><li>Extension browser me response headers inject karta hai</li><li>Server se kuch lena dena nahi hota</li><li>Production me use mat karo — sirf development/test ke liye</li></ul><h3>⚠️ Warning Time!</h3><blockquote><strong><em>Extension is Jugaad, not a permanent fix!</em></strong><em><br>Browser ko bewakoof banana kaafi din tak nahi chalega.</em></blockquote><p>Agar app production me jaa rahi hai:</p><ul><li>Server pe sahi headers configure karo.</li><li>Dev tools ke liye extension theek hai, but public users ke liye nahi.</li></ul><h3>🏁 Summary</h3><p>Scenario Solution Server access hai Add CORS headers Server access nahi Use extension (dev only) Production me Headers hi lagao bhai! Browser error dikha raha Browser ka CORS siren hai</p><h3>💬 One-liner Dev Quote:</h3><blockquote><strong><em>“Browser ne siren bajaya, extension ne chhup kara diya, lekin asli permission toh mummy (server) hi degi!”</em></strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80c3b8b6e2b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install Node.js, Deploy a React-Vite App with Nginx, and Use PM2 on Ubuntu]]></title>
            <link>https://codeguyakash.medium.com/how-to-install-node-js-deploy-a-react-vite-app-with-nginx-and-use-pm2-on-ubuntu-fd348374511e?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd348374511e</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Tue, 25 Feb 2025 19:24:47 GMT</pubDate>
            <atom:updated>2025-02-25T19:34:37.385Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*MNUxwzWaW3uQXLmyvqOnKA.png" /></figure><p>Deploying a React-Vite application on an Ubuntu server with Nginx and managing it using PM2 is a great way to ensure smooth performance. This guide will walk you through the process step by step.</p><h3>Step 1: Install Node.js on Ubuntu</h3><p>First, update the system package list and upgrade existing packages:</p><pre>sudo apt update &amp;&amp; sudo apt upgrade -y</pre><p>Then, install Node.js using NodeSource:</p><pre>curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -<br>sudo apt install -y nodejs</pre><p>Verify the installation:</p><pre>node -v<br>npm -v</pre><h3>Step 2: Generate a Production Build for React-Vite</h3><p>Navigate to your React-Vite project directory:</p><pre>cd /path/to/your-react-project</pre><p>Ensure dependencies are installed:</p><pre>npm install</pre><p>Build the project for production:</p><pre>npm run build</pre><p>This will generate a dist/ folder containing the optimized production files.</p><h3>Step 3: Move Build Files to Nginx Root Directory</h3><p>Move the dist/ folder to a directory accessible by Nginx:</p><pre>sudo mv /path/to/your-react-project/dist /var/www/react-app</pre><p>Set proper ownership and permissions:</p><pre>sudo chown -R www-data:www-data /var/www/react-app<br>sudo chmod -R 755 /var/www/react-app</pre><h3>Step 4: Configure Nginx for React App</h3><p>Create a new Nginx configuration file:</p><pre>sudo nano /etc/nginx/sites-available/react-app</pre><p>Paste the following configuration:</p><pre>server {<br>    listen 80;<br>    server_name _;  # Use your domain or IP if available<br><br>    root /var/www/react-app;<br>    index index.html;<br>    <br>    location / {<br>        try_files $uri /index.html;<br>    }<br><br>    error_page 404 /index.html;<br><br>    # Backend API proxy (3000 port)<br>    location /api/ {<br>        proxy_pass http://localhost:3000/;<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 $scheme;<br>    }<br>}</pre><p>Save the file and enable the configuration:</p><pre>sudo ln -s /etc/nginx/sites-available/react-app /etc/nginx/sites-enabled/</pre><p>If necessary, disable the default Nginx site:</p><pre>sudo rm /etc/nginx/sites-enabled/default</pre><p>Test the configuration and restart Nginx:</p><pre>sudo nginx -t<br>sudo systemctl restart nginx</pre><p>If any errors occur, check logs using:</p><pre>sudo journalctl -xe</pre><h3>Step 5: Allow Traffic Through Firewall</h3><p>Ensure that HTTP traffic is allowed:</p><pre>sudo ufw allow 80/tcp</pre><p>Now, visit your server’s IP in a browser:</p><pre>http://your_server_ip</pre><p>Your React-Vite app should be live! 🚀</p><h3>Step 6: Configure Nginx for a Node.js Backend (Optional)</h3><p>If your React app communicates with a Node.js backend, update the Nginx configuration:</p><pre>location /api/ {<br>    proxy_pass http://localhost:3000/;  # Adjust port as needed<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 $scheme;<br>}</pre><p>Restart Nginx to apply changes:</p><pre>sudo systemctl restart nginx</pre><h3>Step 7: Install and Configure PM2 for Process Management</h3><p>PM2 ensures that your Node.js application keeps running.</p><h3>Install PM2 globally:</h3><pre>sudo npm install -g pm2</pre><h3>Verify installation:</h3><pre>pm2 -v</pre><h3>Start your Node.js app with PM2:</h3><pre>pm2 start app.js</pre><h3>Manage PM2 processes:</h3><pre>pm2 list         # View running applications<br>pm2 restart app  # Restart an app<br>pm2 stop app     # Stop an app<br>pm2 delete app   # Remove an app from PM2</pre><h3>Enable PM2 to restart on reboot:</h3><pre>pm2 startup</pre><p>Run the suggested command that appears, for example:</p><pre>sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u your-user --hp /home/your-user</pre><h3>Save the PM2 process list:</h3><pre>pm2 save</pre><p>Now, even after a reboot, PM2 will ensure your application starts automatically! 🚀</p><p><a href="https://medium.com/u/cda2c3b22edf">Akash (codeguyakash)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd348374511e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[USB Detection in a React Native App]]></title>
            <link>https://codeguyakash.medium.com/usb-detection-in-a-react-native-app-2aad0fa6c7ba?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/2aad0fa6c7ba</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Sat, 22 Feb 2025 17:58:38 GMT</pubDate>
            <atom:updated>2025-02-25T19:32:00.886Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*HuXQXfvpalS91E6qooBGPg.png" /></figure><p>In this article, we will explore how to detect USB devices in a React Native app using a custom native module written in Kotlin. This guide will walk you through the process step by step, explaining how the code works.</p><h3>Introduction</h3><p>React Native does not provide built-in support for USB detection, but we can achieve this functionality by integrating native Android code. By using UsbManager and BroadcastReceiver, we can listen for USB device connections and disconnections.</p><h3>Step 1: Creating the USB Detection Module</h3><p>We will create a custom native module in Kotlin to handle USB device detection.</p><h3>UsbDetectionModule.kt</h3><pre>package com.youapp</pre><pre>import android.content.BroadcastReceiver<br>import android.content.Context<br>import android.content.Intent<br>import android.content.IntentFilter<br>import android.hardware.usb.UsbDevice<br>import android.hardware.usb.UsbManager<br>import com.facebook.react.bridge.*<br>import com.facebook.react.modules.core.DeviceEventManagerModule</pre><pre>class UsbDetectionModule(reactContext: ReactApplicationContext) :<br>    ReactContextBaseJavaModule(reactContext) {</pre><pre>    init {<br>        registerUsbReceiver()<br>    }</pre><pre>    override fun getName(): String {<br>        return &quot;UsbDetection&quot;<br>    }</pre><pre>    @ReactMethod<br>    fun getConnectedUsbDevices(promise: Promise) {<br>        try {<br>            val usbManager = reactApplicationContext.getSystemService(Context.USB_SERVICE) as UsbManager<br>            val devices: HashMap&lt;String, UsbDevice&gt; = usbManager.deviceList as HashMap&lt;String, UsbDevice&gt;</pre><pre>            val deviceNames: WritableArray = Arguments.createArray()<br>            for ((_, device) in devices) {<br>                deviceNames.pushString(device.deviceName)<br>            }</pre><pre>            promise.resolve(deviceNames)<br>        } catch (e: SecurityException) {<br>            promise.reject(&quot;USB_PERMISSION_ERROR&quot;, &quot;USB permission is missing: ${e.message}&quot;)<br>        } catch (e: Exception) {<br>            promise.reject(&quot;USB_ERROR&quot;, &quot;Failed to get USB devices: ${e.message}&quot;)<br>        }<br>    }</pre><pre>    private fun registerUsbReceiver() {<br>        val filter = IntentFilter().apply {<br>            addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)<br>            addAction(UsbManager.ACTION_USB_DEVICE_DETACHED)<br>        }<br>        reactApplicationContext.registerReceiver(usbReceiver, filter)<br>    }</pre><pre>    private val usbReceiver: BroadcastReceiver = object : BroadcastReceiver() {<br>        override fun onReceive(context: Context, intent: Intent) {<br>            val action = intent.action ?: return<br>            reactApplicationContext.getSystemService(Context.USB_SERVICE) as UsbManager<br>            val device: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)</pre><pre>            when (action) {<br>                UsbManager.ACTION_USB_DEVICE_ATTACHED -&gt; {<br>                    if (device != null) {<br>                        sendEvent(&quot;USB_ATTACHED&quot;, device.deviceName)<br>                    }<br>                }<br>                UsbManager.ACTION_USB_DEVICE_DETACHED -&gt; {<br>                    if (device != null) {<br>                        sendEvent(&quot;USB_DETACHED&quot;, device.deviceName)<br>                    }<br>                }<br>            }<br>        }<br>    }</pre><pre>    private fun sendEvent(eventName: String, deviceName: String) {<br>        reactApplicationContext<br>            .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)<br>            ?.emit(eventName, deviceName)<br>    }<br>}</pre><h3>Step 2: Creating the USB Detection Package</h3><p>We need to package the module so it can be accessed from React Native.</p><h3>UsbDetectionPackage.kt</h3><pre>package com.youapp</pre><pre>import com.facebook.react.ReactPackage<br>import com.facebook.react.bridge.NativeModule<br>import com.facebook.react.bridge.ReactApplicationContext<br>import com.facebook.react.uimanager.ViewManager</pre><pre>class UsbDetectionPackage : ReactPackage {<br>    override fun createNativeModules(reactContext: ReactApplicationContext): List&lt;NativeModule&gt; {<br>        return listOf(UsbDetectionModule(reactContext))<br>    }</pre><pre>    override fun createViewManagers(reactContext: ReactApplicationContext): List&lt;ViewManager&lt;*, *&gt;&gt; {<br>        return emptyList()<br>    }<br>}</pre><h3>Step 3: Registering the Package in the Main Application</h3><p>We need to register our new package in MainApplication.kt.</p><h3>MainApplication.kt</h3><pre>package com.youapp</pre><pre>import android.app.Application<br>import com.facebook.react.PackageList<br>import com.facebook.react.ReactApplication<br>import com.facebook.react.ReactHost<br>import com.facebook.react.ReactNativeHost<br>import com.facebook.react.ReactPackage<br>import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load<br>import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost<br>import com.facebook.react.defaults.DefaultReactNativeHost<br>import com.facebook.react.soloader.OpenSourceMergedSoMapping<br>import com.facebook.soloader.SoLoader</pre><pre>class MainApplication : Application(), ReactApplication {</pre><pre>  override val reactNativeHost: ReactNativeHost =<br>      object : DefaultReactNativeHost(this) {<br>        override fun getPackages(): List&lt;ReactPackage&gt; =<br>            PackageList(this).packages.apply {<br>              add(UsbDetectionPackage()) // Register here <br>            }</pre><pre>        override fun getJSMainModuleName(): String = &quot;index&quot;<br>        override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG<br>        override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED<br>        override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED<br>      }</pre><pre>  override val reactHost: ReactHost<br>    get() = getDefaultReactHost(applicationContext, reactNativeHost)</pre><pre>  override fun onCreate() {<br>    super.onCreate()<br>    SoLoader.init(this, OpenSourceMergedSoMapping)<br>    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {<br>      load()<br>    }<br>  }<br>}</pre><h3>Step 4: Using the USB Detection Module in React Native</h3><p>We will use the module in our React Native app.</p><h3>App.tsx</h3><pre>import { NativeEventEmitter, NativeModules } from &#39;react-native&#39;;</pre><pre>const UsbDetection = NativeModules.UsbDetection;<br>const usbEmitter = new NativeEventEmitter(UsbDetection);</pre><pre>useEffect(() =&gt; {<br>  usbEmitter.addListener(&#39;USB_ATTACHED&#39;, deviceName =&gt; {<br>    console.log(&#39;USB Connected:&#39;, deviceName);<br>  });</pre><pre>  usbEmitter.addListener(&#39;USB_DETACHED&#39;, deviceName =&gt; {<br>    console.log(&#39;USB Disconnected:&#39;, deviceName);<br>  });</pre><pre>  return () =&gt; {<br>    usbEmitter.removeAllListeners(&#39;USB_ATTACHED&#39;);<br>    usbEmitter.removeAllListeners(&#39;USB_DETACHED&#39;);<br>  };<br>}, []);</pre><h3>Conclusion</h3><p>By following these steps, you can successfully detect USB devices in your React Native application. This approach helps in real-time monitoring of USB device connections and disconnections using Kotlin and React Native.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aad0fa6c7ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Web Development Power: From ‘npm init’ to Your First Express.js App]]></title>
            <link>https://codeguyakash.medium.com/unlocking-web-development-power-from-npm-init-to-your-first-express-js-app-310ec460171f?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/310ec460171f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[express]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[codeguyakash]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Wed, 24 Apr 2024 13:41:38 GMT</pubDate>
            <atom:updated>2024-04-24T13:42:50.385Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a7Q7LE44Z8FvywkxCHqNBA.png" /></figure><p>Picture this: you’ve got a brilliant idea for a web application — maybe it’s a task tracker, a social platform, or the next big online game. But, how do you turn that idea into reality? That’s where the dynamic duo of Node.js and Express.js come to the rescue!</p><p><strong>Setting the Stage: ‘npm init’</strong></p><p>Every journey starts with a single step. In web development, that often means a simple command: npm init -y . Here&#39;s what happens behind the scenes:</p><ul><li><strong>Node Package Manager (npm):</strong> This handy tool helps you manage all the awesome code libraries you’ll use in your project.</li><li><strong>The ‘init’ command:</strong> This tells npm to set up a house for your project — the package.json file. It&#39;s like the blueprint, listing your project&#39;s name, what other tools you use, and more.</li><li><strong>The ‘-y’ flag:</strong> This is a shortcut telling npm, “Don’t ask me questions, just use the basics!”</li></ul><p><strong>Example:</strong></p><pre>{<br>  &quot;name&quot;: &quot;your-folder-name&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;basic express app&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&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;Akash (codeguyakash)&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;<br>}</pre><p><strong>Introducing Express.js: The Streamlined Web Architect</strong></p><p>Node.js provides the raw power for building web servers, but Express.js makes the process elegant and organized. Think of it this way:</p><ul><li><strong>Node.js is the engine:</strong> It handles the technical grunt work of receiving requests and sending responses.</li><li><strong>Express.js is the design expert:</strong> It gives you the tools to shape routes (think of them as the roads of your application), handle different types of requests (like GET or POST), and make your app look pretty.</li></ul><p><strong>Building Your First Express App: A Beginner’s Blueprint</strong></p><p>Let’s create a super simple website. Imagine we’ll call it index.js:</p><p>JavaScript</p><pre>const express = require(&#39;express&#39;);<br>const app = express();<br><br>const port = process.env.PORT || 3000;<br><br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello from Express!&#39;);<br>}); <br> <br>app.listen(port, () =&gt; {<br>  console.log(`Server listening on port ${port}`);<br>});</pre><p>Let’s break this down:</p><ul><li><strong>The Magician ‘require()’:</strong> We bring in the mighty Express.js library.</li><li><strong>The Application: ‘app’:</strong> We create an Express application.</li><li><strong>A Warm Welcome: ‘app.get(…)’:</strong> We make a route for the homepage (‘/’). When someone visits, it sends the text “Hello from Express!”.</li><li><strong>Ears Open: ‘app.listen()’:</strong> We tell our server to start listening on a port.</li></ul><p><strong>The Grand Reveal: Running Your Creation</strong></p><ul><li><strong>Save your </strong>index.js<strong> file.</strong></li><li><strong>Command and Conquer:</strong> Open your terminal and run node index.js.</li><li><strong>Visit </strong>http://localhost:3000 in your web browser and witness your &quot;Hello from Express!&quot; greeting.</li></ul><p><strong>This is Just the Beginning</strong></p><p>Think of this as baking your very first cookie. From here, you can:</p><ul><li><strong>Craft more routes:</strong> Make different “pages” on your website.</li><li><strong>Upgrade with middleware:</strong> Add functions to handle logins, file uploads, and more.</li><li><strong>Beautiful templates:</strong> Plug in engines like EJS to make your pages dynamic.</li></ul><p><strong>Want to explore advanced topics like Node.js Worker Threads?</strong></p><p><a href="https://codeguyakash.medium.com/threads-in-node-js-unlocking-the-power-of-parallel-processing-74a0ada5f92e">Threads in Node.js: Unlocking the Power of Parallel Processing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=310ec460171f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Express.js: Building Web Applications with Ease]]></title>
            <link>https://codeguyakash.medium.com/understanding-express-js-building-web-applications-with-ease-e11d4979a5be?source=rss-cda2c3b22edf------2</link>
            <guid isPermaLink="false">https://medium.com/p/e11d4979a5be</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mern-stack]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator>
            <pubDate>Wed, 24 Apr 2024 13:16:46 GMT</pubDate>
            <atom:updated>2024-04-24T13:16:46.247Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is Express.js?</strong></p><p>Express.js is a web application framework for Node.js. If Node.js is the engine of your web server, think of Express.js as a streamlined toolkit that helps you build things quickly and easily. It handles the complexities of routing (mapping URLs to actions), templating (creating dynamic HTML pages), and much more, giving you a solid foundation for your web applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XwUj4VC20Q8xR_EcnH9AnQ.png" /></figure><p><strong>Why Use Express.js?</strong></p><ol><li><strong>Simplicity:</strong> Express offers a minimalist approach, giving you the freedom to structure your application the way you want.</li><li><strong>Flexibility:</strong> It works seamlessly with many other Node.js modules available, letting you pick the tools that best suit your project.</li><li><strong>Performance:</strong> Express.js is built on Node.js, giving you great performance and scalability for web apps.</li><li><strong>Popularity:</strong> Huge community support means lots of tutorials, help, and resources to learn from.</li></ol><p><strong>Core Concepts</strong></p><ol><li><strong>Routing:</strong> Express lets you define “routes” — these are patterns in URLs. For example</li><li>This means, that when someone visits your website’s root (‘/’), they’ll see the text “Hello from the home page!”.</li></ol><pre>app.get(&#39;/&#39;, (req, res) =&gt; {<br>    res.send(&#39;Hello from the home page!&#39;);<br>});</pre><ol><li><strong>Middleware:</strong> Think of middleware as functions that modify incoming requests or outgoing responses. They’re like checkpoints along the route of your application. Common uses:</li></ol><p><strong><em>i). Logging requests</em></strong></p><p><strong><em>ii). Authentication (checking if a user is logged in)</em></strong></p><p><strong><em>iii). Parsing data from forms</em></strong></p><ol><li><strong>Templating Engines:</strong> Express lets you plug in templating engines (like EJS, Pug, or Handlebars) These help you create dynamic HTML pages by filling in data on the fly.</li></ol><pre>const express = require(&#39;express&#39;);<br>const app = express();<br>const port = 3000;<br><br>// A route for the homepage<br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello, Express!&#39;);<br>}); <br><br>// Start listening for requests<br>app.listen(port, () =&gt; {<br>  console.log(`Example app listening at http://localhost:${port}`); <br>});</pre><p><strong>Explanation</strong></p><ul><li>We start by bringing in the ‘express’ module.</li><li>The app object is our main Express application.</li><li>We define a route for the homepage (‘/’). When someone visits this route, the function sends a text response.</li><li>Finally, we start the server listening on port 3000.</li></ul><p><strong>Next Steps</strong></p><p>This is just a taste of Express.js! To learn more, explore:</p><ul><li><strong>Express.js Official Docs:</strong> The best source (<a href="https://expressjs.com/">https://expressjs.com/</a>)</li><li><strong>Building Routes for Different Request Types (GET, POST, etc.):</strong> Shape how your application handles user interactions.</li><li><strong>Working with Templating Engines:</strong> Make your pages dynamic.</li><li><strong>Using Middleware for Common Tasks:</strong> Add functionality at different points.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e11d4979a5be" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>