<?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"><channel><title><![CDATA[Kelvin Ho's Develpment Blog]]></title><description><![CDATA[Kelvin Ho's Develpment Blog]]></description><link>https://blog.kelvinho.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 27 May 2026 16:33:21 GMT</lastBuildDate><atom:link href="https://blog.kelvinho.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Debugging TypeScript backend service: Step-by-Step guide]]></title><description><![CDATA[Background
Node and Express.js are increasingly popular for developing backend APIs. Although building a RESTful API with Express.js is straightforward, not all developers know how to debug applicatio]]></description><link>https://blog.kelvinho.dev/debugging-typescript-backend-service-step-by-step-guide</link><guid isPermaLink="true">https://blog.kelvinho.dev/debugging-typescript-backend-service-step-by-step-guide</guid><dc:creator><![CDATA[Kelvin Ho]]></dc:creator><pubDate>Wed, 18 Mar 2026 22:15:32 GMT</pubDate><content:encoded><![CDATA[<h1>Background</h1>
<p>Node and Express.js are increasingly popular for developing backend APIs. Although building a RESTful API with Express.js is straightforward, not all developers know how to debug applications in Visual Studio Code. This article shares my insights on debugging an Express backend service, aiming to assist other developers.</p>
<h2>Bootstrap a backend API</h2>
<p>Before we can debug, we need a RESTful API project using Express.js. If you haven't had one yet, bootstrapped it with:</p>
<pre><code class="language-shell">mkdir my-api &amp;&amp; cd my-api npm init -y
npm install express dotenv cors 
npm install -D typescript tsx @types/node @types/express @types/cors
npx tsc --init
</code></pre>
<p>This will create an RESTful api project.</p>
<p>Create a folder <code>src</code> and created two files <code>app.ts</code> and <code>server.ts</code>.</p>
<pre><code class="language-plaintext">my-api/
|-- src/
|   |-- app.ts
|   |-- server.ts
</code></pre>
<p>Setup a GET endpoint <code>/</code> in <code>app.ts</code> returning a json that indicates the API is running.</p>
<pre><code class="language-typescript">import express from 'express';
import type { Application, Request, Response } from 'express';
import cors from 'cors';

const app: Application = express();

app.use(cors());
app.use(express.json());

app.get('/', (req: Request, res: Response) =&gt; {
  res.status(200).json({ message: 'API is running smoothly' });
});

export default app;
</code></pre>
<p>The <code>src/server.ts</code> specifies the application to listen to port 3000.</p>
<pre><code class="language-typescript">import app from './app';

const PORT = 3000;

app.listen(PORT, () =&gt; {
  console.log(`🚀 Server ready at: http://localhost:${PORT}`);
});
</code></pre>
<p>In <code>package.json</code>, add the scripts to develop, build and start the application.</p>
<pre><code class="language-json"> "scripts": { 
   "dev": "tsx watch src/server.ts", 
   "build": "tsc", 
   "start": "node dist/server.js" 
  }
</code></pre>
<p>The above config will allow you to run <code>npm run dev</code> to start the application.</p>
<h2>Create vscode/launch.json</h2>
<p>Create <code>vscode/launch.json</code> with the following content:</p>
<pre><code class="language-json">{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Backend",
      "request": "launch",
      "skipFiles": ["&lt;node_internals&gt;/**"],
      "type": "node",
      "runtimeExecutable": "npm",
      "runtimeArgs": ["run", "dev"]
    }
  ]
}
</code></pre>
<blockquote>
<p>This config tells VS Code to attach the debugger once your application is started by <code>npm run dev</code>.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Debugging React Apps with Vite in Visual Studio Code: Step-by-Step]]></title><description><![CDATA[Background
Modern React projects increasingly use Vite for faster development, but debugging setups - especially in Visual Studio Code - can be confusing for some beginners. This article documents my ]]></description><link>https://blog.kelvinho.dev/debugging-react-apps-with-vite-in-visual-studio-code-step-by-step</link><guid isPermaLink="true">https://blog.kelvinho.dev/debugging-react-apps-with-vite-in-visual-studio-code-step-by-step</guid><dc:creator><![CDATA[Kelvin Ho]]></dc:creator><pubDate>Wed, 18 Mar 2026 00:31:11 GMT</pubDate><content:encoded><![CDATA[<h2>Background</h2>
<p>Modern React projects increasingly use Vite for faster development, but debugging setups - especially in Visual Studio Code - can be confusing for some beginners. This article documents my hands-on learning experience debugging a React app built with Vite in VS Code, with the goal of helping other developers overcome similiar challenges more quickly and effectively.</p>
<h2>Step 1: Setting Up a React Project with Vite</h2>
<p>Before we can debug, we need a React project running with Vite. If you haven't created one yet, you can bootstrap it with:</p>
<pre><code class="language-shell">npm create vite@latest frontend 
cd frontend 
npm install 
npm run dev
</code></pre>
<p>This will start your app at <code>http://localhost:5173</code></p>
<h2>Step 2: Configure VS Code for Debugging</h2>
<p>To debug your React app in VS Code, we'll use a combination of a <strong>launch configuration</strong> and a <strong>task</strong> to start Vite automatically.</p>
<h3>2.1 Add a Launch Configuration</h3>
<p>Create <code>.vscode/launch.json</code> with the following content:</p>
<pre><code class="language-json">{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Debug frontend",
      "url": "http://localhost:5173",
      "webRoot": "${workspaceFolder}/frontend",
      "preLaunchTask": "Start Vite App",
      "skipFiles": [
        "&lt;node_internals&gt;/**",
        "**/node_modules/**",
        "**/@vite/client/**"
      ]
    }
  ]
}
</code></pre>
<blockquote>
<p>This configuration tells VS Code to launch Chrome and attach it to your React app running at <a href="http://localhost:5173">http://localhost:5173</a>.</p>
</blockquote>
<h3>2.2 Add a Task to Start the App</h3>
<p>Create <code>.vscode/tasks.json</code> to include the task to start the React app.</p>
<pre><code class="language-json">{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Start Vite App",
      "type": "shell",
      "command": "npm run dev",
      "options": {
        "cwd": "${workspaceFolder}/frontend"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "presentation": {
        "reveal": "always",
        "panel": "shared"
      },
      "problemMatcher": []
    }
  ]
}
</code></pre>
<blockquote>
<p>This task starts your Vite development server whenever you start debugging in VS Code.</p>
</blockquote>
<h3>2.3 Link the Task in Launch Configuration</h3>
<p>Ensure the <code>preLaunchTask</code> in <code>launch.json</code> matches the task label "<code>Start Vite App</code>". This makes VS Code start your app automatically before launching the debugger.</p>
<h3>2.4 Update Task Configuration</h3>
<p>Currently, VS Code doesn't recognize when your task completes, prompting a "Debug anyway" popup. To inform VS Code that the React application has finished starting, update <code>tasks.json</code> by adding <code>isBackground: true</code> and a <code>problemMatcher</code> that monitors the terminal output for the "ready" message (e.g., VITE v5.x.x ready in ...).</p>
<p>So, the final <code>tasks.json</code> should look like:</p>
<pre><code class="language-json">{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Start Vite App",
      "type": "shell",
      "command": "npm run dev",
      "isBackground": true, // &lt;--- CRITICAL: Tells VS Code not to wait for exit
      "options": {
        "cwd": "${workspaceFolder}"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "presentation": {
        "reveal": "always",
        "panel": "shared"
      },
      // This regex watches the console for Vite's startup message
      "problemMatcher": [
        {
          "pattern": [
            {
              "regexp": ".",
              "file": 1,
              "location": 2,
              "message": 3
            }
          ],
          "background": {
            "activeOnStart": true,
            "beginsPattern": ".*VITE.*",
            "endsPattern": ".*ready in.*|.*Local:.*" // &lt;--- Signal that task is "done"
          }
        }
      ]
    }
  ]
}
</code></pre>
]]></content:encoded></item><item><title><![CDATA[How to Debug JavaScript and TypeScript in VS Code: A Step-by-Step Guide]]></title><description><![CDATA[Background
In recent years I started working more with TypeScript and React to build modern back-end and front-end applications. While these technologies are powerful and improve developer productivit]]></description><link>https://blog.kelvinho.dev/how-to-debug-javascript-and-typescript-in-vs-code-a-step-by-step-guide</link><guid isPermaLink="true">https://blog.kelvinho.dev/how-to-debug-javascript-and-typescript-in-vs-code-a-step-by-step-guide</guid><dc:creator><![CDATA[Kelvin Ho]]></dc:creator><pubDate>Tue, 17 Mar 2026 05:04:51 GMT</pubDate><content:encoded><![CDATA[<h1>Background</h1>
<p>In recent years I started working more with TypeScript and React to build modern back-end and front-end applications. While these technologies are powerful and improve developer productivity in many ways, I found that debugging them was not always straightforward.</p>
<p>In my earlier work, debugging Java or .NET applications in IntelliJ or Microsoft Visual Studio was usually quite predictable. However, with modern JavaScript or TypeScripts applications, the combination of asynchronous code, browser behavior, frameworks and build tools sometimes makes it difficult to understand what is happening when something goes wrong. I often found myself relying on console.log statements or switch between different tools just to trace a small issue.</p>
<p>Over time, I realized that many of these frustrations came from not fully utilizing the debugging capabilities already available in Visual Studio Code. This article is written based on my own learning process. I want to document the tehcniques and setups that helped me debug JavaScript / TypeScript applications more effectively in VS Code. My hope is that these practical tips can help other developers who may have faced similiar challenges.</p>
<h2>Debugging a JavaScript Application Running on Node.js</h2>
<p>Before diving into more complex scenarios such as debugging React or full-stack applications, it is helpful to start with the most basic case: debugging a JavaScript application running on Node.js.</p>
<p>Node.js provides built-in support for debugging, and Visual Studio Code integrates seamlessly with it. This makes it possible to set breakpoints, step through code, inspect variables, and evaluate expressions directly within tvhe editor.</p>
<p>To demonstrate the basics, let's start with a very simple but buggy Node.js program.</p>
<pre><code class="language-javascript">// app.js
function calculateTotal(items) {
  console.log("Calculating...");
  let total = 0;
  for (let i = 1; i &lt;= items.length; i++) {
    total += items[i].price;
  }
  return total;
}

const myCart = [
  { name: "Laptop", price: 1200 },
  { name: "Mouse", price: 25 },
  { name: "Keyboard", price: 75 },
];

const finalPrice = calculateTotal(myCart);
console.log("Final Price: ", finalPrice);
</code></pre>
<p>The 3-Step Debugger</p>
<p>First, set a Breakpoint; press F5; choose "Node.js". That's it. Your script will start running and pause at your breakpoint.</p>
<h2>Debugging a TypeScript Application in VS Code</h2>
<p>Debugging Typescript can feel slightly more complex than standard JavaScript because the code must be transpiled before execution. However, with the right tools, you can achieve a seamless "set it and forget it" workflow.</p>
<ol>
<li><p><strong>The Modern Approach: Using</strong> <code>tsx</code><br />Instead of manually compiling files with tsc and then running them with Node, we can use <strong>tsx</strong> (TypeScript Execute). It's fast, zero-config way to run TypeScript files directly in a Node.js environment.<br />First, add it to your project as a development dependency:<br /><code>npm install -D tsx</code></p>
</li>
<li><p><strong>A Sample Script</strong><br />To test our debugger, let's use a simple function in a file named <code>src/main.ts</code>:</p>
<pre><code class="language-typescript">function helloWorld(): void {
  console.log("Hello, world!");
}

helloWorld();
</code></pre>
</li>
<li><p><strong>Configuring the Launch Blueprint</strong><br />To bridge the gap between your code and the VS Code debugger, you need a <code>launch.json</code> file. This lives inside the <code>.vscode</code> folder at the root of your project.</p>
<p>This file acts as a configuration blueprint, instructing VS Code exactly which executable to use and which arguments to pass.</p>
<p>Create or update .<code>vscode/launch.json</code> with the following:</p>
<pre><code class="language-json">{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Execute main.ts",
      "runtimeExecutable": "tsx",
      "runtimeArgs": ["src/main.ts"],
      "request": "launch",
      "skipFiles": ["&lt;node_internals&gt;/**"],
      "type": "node"
    }
  ]
}
</code></pre>
</li>
<li><p><strong>Start Debugging</strong> With this configuration in place, debugging is simple:</p>
<ul>
<li><p>Open <code>scr/main.ts</code>.</p>
</li>
<li><p>Click to the left of line numbers to set a breakpoint (the red dot.).</p>
</li>
<li><p>Press <strong>F5</strong> or go to the "Run and Debug" tab and click the Play button.</p>
</li>
</ul>
</li>
</ol>
]]></content:encoded></item></channel></rss>