Node.js
AWS
Remote Debugging
Cloud Hosting
Debugging Techniques

Remotely debugging my node app that is hosted on AWS

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Overview

Developing and deploying applications in the cloud, such as AWS, offers unmatched scalability and flexibility. However, when it comes to debugging node applications in this environment, there are unique challenges to consider. This guide provides a comprehensive walkthrough on remotely debugging a Node.js app running on AWS.

Prerequisites

Before diving into the debugging process, ensure the following prerequisites are met:

  • Your Node.js application is running on an AWS EC2 instance.
  • SSH access to the EC2 instance is configured.
  • Node.js and npm are installed on the local machine.
  • Familiarity with AWS services such as EC2 and CloudWatch.

Remote Debugging Setup

Step 1: Configure the EC2 Instance

  1. Open Port in the Security Group:
    • To enable remote debugging, you'll need to open a port (e.g., 9229) in the security group associated with your EC2 instance.
    • Navigate to the EC2 dashboard, and select the security group.
    • Edit inbound rules to add a new rule:
      • Type: Custom TCP
      • Port Range: 9229
      • Source: Anywhere or My IP (for security, restrict access to specific IPs)
  2. Install Node.js Inspector:
    The Node Inspector is a popular tool for debugging Node.js applications:
  • The `0.0.0.0` allows connections from any IP, which is vital for remote debugging.
  • The port `9229` must match the port opened on the security group.
    • Type `chrome://inspect` in the address bar.
    • Click on "Configure" and add your remote target, inputting the public DNS and the port (`ec2-x-x-x-x.compute-1.amazonaws.com:9229`).
    • Once you've configured your target, it's listed under Remote Target.
    • Click "Inspect" to open Chrome DevTools linked to your remote Node.js instance.
    • Go to the VS Code marketplace and install "Debugger for Chrome".
    • Open the debug view (Ctrl+Shift+D), click the gear icon, and choose "Node.js" to create a `launch.json` file.
    • Configure the file as follows:
    • Select "Attach to Remote" in the debug panel and hit F5 to start debugging.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.