Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    React Native

    Build Real-World React Native App #7: Send Feedback with Formik, Yup, Firebase Cloud Function and Sendgrid

    JavaScript

    Build Real-world React Native App #1: Splash screen and App Icon

    Programming

    Programming Patterns. Introduction

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Wednesday, November 12
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / Node.js / Node.js Lessons / Node.js Lesson 13: Debugging in Node.js
    JavaScript

    Node.js Lesson 13: Debugging in Node.js

    Mohammad Shad MirzaBy Mohammad Shad MirzaDecember 18, 2020Updated:January 5, 2021No Comments5 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Node.js Lesson 13: Debugging in Node.js
    Node.js Lesson 13: Debugging in Node.js
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Node.js Lesson 13: Debugging in Node.js
    Node.js Lesson 13: Debugging in Node.js

    Hey everyone. Debugging is an essential part of programming, our program hardly runs correctly in the first run and we spend most of our time figuring out what’s wrong with our code. To quote Maurice Wilkes here:

    “As soon as we started programming, we found to our surprise that it wasn’t as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.”– Maurice Wilkes

    Since debugging is this important, it’s almost a skill that we must learn to be a better programmer and ship features quickly. In this lesson, we will learn about debugging a node application. We will learn about different ways which can be employed to debug node application with ease. Here’s a list of things we will cover in this article:

    • JavaScript Debugger
    • Chrome DevTools
    • –inspect command
    • –inspect-brk command
    • IDE

    Let’s start 🚀

    JavaScript Debugger

    Node has a built-in debugger which can be accessed by adding a debugger statement in the code itself. Nodejs will pause the execution of the process when it encounters this statement. We will then go ahead and inspect the app state at that particular point in time to see what is causing the issue. Let’s consider this example:

    const url = require('url');
     
    const server = http.createServer();
     
    server.on('request', function(req, res) {
        const urlParsed = url.parse(req.url, true);
     
        if (req.method == 'GET' && urlParsed.pathname == '/echo' && urlParsed.query.message) {
            res.end(urlParsed.query.message );
            return;
        }
     
        res.statusCode = 404;
        res.end('Not Found');
    });
     
    server.listen(1337);
    console.log("Server is running");

    It’s a basic echo server that is not functioning well. We can add a debugger statement and stop the process.

    const url = require('url');
     
    const server = http.createServer();
     
    server.on('request', function(req, res) {
        const urlParsed = url.parse(req.url, true);
        debugger; // <-- Debugger added
        if (req.method == 'GET' && urlParsed.pathname == '/echo' && urlParsed.query.message) {
            res.end(urlParsed.query.message );
            return;
        }
     
        res.statusCode = 404;
        res.end('Not Found');
    });
     
    server.listen(1337);
    console.log("Server is running");

    Now, you can run the script and it will add a breakpoint exactly where we added the debugger statement. Run this command to launch the script:

    node debug script.js

    ou can see the required info like variable value, function scope, etc in the console. The debugging mode provides us other helpful commands like cont which we can use to continue the execution of the program.

    Read More:  Node.js Lesson 7: Console Module

    Chrome DevTools

    While the above strategy works well, but it still needs some extra work on our end. There is a much better alternative in the form of Chrome DevTools. Since Chrome is the most widely used web browser among the developer, it equips us with some really useful features.

    You can open chrome and run your program. Right-click and go to inspect to open the Chrome DevTools. Here is what you can do with it:

    • Search the codebase
    • Use the debugger statement explained in the first section right in the DevTools itself.
    • Edit HTML and CSS to debug frontend code.
    • Clear cookies and cache
    • Throttle network speed to test on a slow connection.
    • Check network requests.
    • Monitor Performance using Profiler.

    –inspect command

    You can start your node application with –inspect command and a Node.js process will start listening for a debugging client. By default, it will listen to the host and port 127.0.0.1:9229. Once started, programs like Chrome DevTools, Microsoft Edge and VS Code, WebStorm, Eclipse, etc can be connected to the debugger process to inspect further. Example:

    node --inspect server.js

    –inspect-brk command

    The strategies mentioned above are good as long as we can run the program. But what if the program itself starts crashing. This is likely to happen in the case of an undefined variable or an unknown function call. Consider this example:

    server.on('request', function(req, res) {
        var urlParsed = url.parse(req.url, true);
     
        randomFunction(); // this function doesn't exist
     
        if (req.method == 'GET' && urlParsed.pathname == '/echo' && urlParsed.query.message) {
            res.end(urlParsed.query.message );
            return;
        }
     
        res.statusCode = 404;
        res.end('Not Found');
    });

    In the above code, the function randomFunction() doesn’t exist and will cause the program to crash. We can’t use the debugger statement since we need the program to run first so that we can pause later and inspect.

    Read More:  Ultimate Reading List for Developers | 40 Web Development Books

    You can start your node application with the –inspect-brk command and it will add a breakpoint before the user code starts. This strategy helps understand the cause in the scenario mentioned above.

    IDE

    Moderns IDEs like VS Code and WebStorm come with an inbuilt debugger which can be used to find the error in our souse code. While the process is almost the same in all the IDEs, they slightly differ in terms of GUI. We will talk about VS Code here.

    VS Code has a debugger tab on the left sidebar, you can this to access the debugging window. You will see a button to Launch Program with a bunch of options to pause, reload, stop, go back, go forward buttons on the top right corner. This command helps us time travel in the nodejs execution and find the cause of the error. There is also a DEBUG CONSOLE where you can see the relevant information about the process.

    VS Code debugging window
    VS Code debugging window

    These are all the methods you can employ for your debugging process. Feel free to choose according to the task and your preference. You will be good with Chrome DevTools alone since it’s an all-in-one package but it’s good to know all other methods just in case if you have to use one. That’s it for this article. I hope you learned something. See you soon in the next lesson.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Mohammad Shad Mirza
    • X (Twitter)
    • LinkedIn

    JavaScript lover working on React Native and committed to simplifying code for beginners. Apart from coding and blogging, I like spending my time sketching or writing with a cup of tea.

    Related Posts

    Streamlining Resource Allocation for Enhanced Project Success

    December 18, 2024

    Conducting Effective Post-Project Evaluations: A Guide

    December 16, 2024

    Strategies for Keeping Projects on Track and Meeting Deadlines

    December 10, 2024

    Comments are closed.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Java January 9, 2024

    Sending Emails in Java Applications: A Comprehensive Guide to JavaMail and SMTP Configuration

    The JavaMail API, part of the Java EE (Enterprise Edition) platform, simplifies the process of sending and receiving emails in Java applications. It provides a set of classes and interfaces for working with email protocols, making it a go-to solution for developers looking to implement robust email functionality.

    23. Уроки Node.js. Домены, “асинхронный try..catch”. Часть 3.

    November 18, 2016

    Mastering B2B Lead Generation: Your Complete Guide

    December 20, 2024

    Overview of FREE Python Programming Courses for Beginners

    September 9, 2019

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    Leveraging Lean Startup Methodology for Business Growth Success

    Startups December 1, 2024

    D3.js and Angular/Vue.js Integration

    Programming November 29, 2017

    Автоматическое добавление в задачи ссылок на коммиты

    Wiki June 25, 2016

    Top 11 Django Interview Questions

    JavaScript February 18, 2019

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    JavaScript

    Rendering Patterns: Static and Dynamic Rendering in Nextjs

    Interview

    How to Hire a Freelance Web Developer: Things to Look For and Avoid

    Soshace

    Happy New 2020 Year!

    Most Popular

    TOP SQL & Database Courses [Plus a List of Free SQL Courses]

    Beginners

    Strategies for Enhancing Customer Retention in Startups

    Startups

    The Critical Role of Code Reviews in Software Development

    Programming
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.