Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Facebook Ads

    How Facebook Ads Can Skyrocket Your Home Services Bookings

    Wiki

    Преимущество в знаниях

    CSS

    8 Best Bootstrap UI Kits – World’s Most Popular & Free UI Frameworks

    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, September 10
    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 / Startups / 14. Node.js Lessons. Script Debugging pt. 2
    Startups

    14. Node.js Lessons. Script Debugging pt. 2

    Ivan RastvorovBy Ivan RastvorovOctober 4, 2016Updated:April 5, 2019No Comments6 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    14. Node.js Lessons. Script Debugging pt. 2
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link

    continue

    Let’s continue our debug lesson. Let us learn another essential debugging scenario, in particular – debugging with errors in JavaScript. For example, while handling a request:

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

    there is an unknown call WTF()  or something else that makes JavaScript fail. Let me launch this server. I open the debugger page in my browser. Now if I follow the server url, no debugging will happen because JavaScript will simply fail. In order to debug JavaScript, you can open your debugger and click the same commands as we would select in a browser debugger. It means we need to activate this code pause button. Now I move to the following page: http://127.0.0.1:1337/, and the debugger stops me on the error WTF.

    Let us look at one more debugging example – console utilities. The file pow.js contains the level calculation using a recursive function:

    function pow(x, n) {
        if (n < 0) {
            return x
        }
        var result = x* pow(x, n-1);
        return result;
    }
    
    console.log( pow(2, 3) );
    

    Being called it should output 23 – node pow.js, but shows 32 instead of 8. So, what’s the reason? To see what’s going on we will try to launch a debugger node debug pow.js. Now, if I try to launch Node-inspector, it will get launched. But in practice, nothing will be debugged. Why? As we understand what’s going on, we can easily explain this thing. Node got launched, opened an access to a port 5858, executed the script – and that’s all, Node has finished its work, it’s outputted everything. No Node-inspector will manage to get connected to it just because it isn’t launched. The Port 5858 is closed. What should we do? The thing we really need at the moment is another debug-brk flag.

    node –debug-brk pow.js
    It immediately launches the script by entering the pause state. At start it activates a debugger and waits till someone gets connected to it and gives a command to continue its work. To make sure, let us re-launch Node-inspector and I will enter the developing tools via Chrome. I open the respective url and see where the current pause has happened:

    function pow(x, n) {
        if (n < 0) {
            return x
        }
        var result = x* pow(x, n-1);
        return result;
    }
    
    console.log( pow(2, 3) );
    

    Further I will provide some more details to those of you who, probably, faces these development tools for the first time.

    Read More:  Oksana Trypolska: I Don't Know Any Person Who, After Working Remotely, Returned to the Office

    screen_captute_node14

    We see the current script; the information and control buttons are on the right. Now I will push the button with an arrow down (F11). It will bring me to the next command. Click it. Where are we now? This moment is rather ambiguous. The thing is that when I try to connect the console object, Node.js does require:
    return NativeModule.require(‘console’);

    This built-in object does not get launched by default – you need to connect it. We are barely interested in connecting console, that’s why I will push another button, with an arrow up. It means the execution process needs to be continued, but it will stop whenever you log out this function. So, press it.

    Now console is connected. The next call is to refer to pow. Press an arrow down. Now we’re inside the pow function.

    Now every next pressing of an arrow down will transfer the control inside the nested calls. Pay your attention to Call Stack on the right – it grows. It is a sequence of the function’s nested calls, which have brought them to the current state. In this case, we are interested only in pow.js. It is the only file made by us, the others are built-in modules. Initially it was a console, then another call followed by the next. They differ from each other with their local variables.

    Our further debugging steps are quite obvious, that’s why we move to the next debugging method – IDE. We’ll use WebStorm as our IDE. To launch debugging, we’ll take this suitable ready-to-use configuration:

    var http = require('http');
    var url = require('url');
    
    var server = http.createServer();
    
    server.on('request', function(req, res) {
        var urlParsed = url.parse(req.url, true);
        debugger
        
        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"); 
    

    The only thing is that we need to launch Node, not a supervisor. Launch a debugger and see what’s happened in the console. At its start in a debugging mode WebStorm adds the respective parameter debug-brk to Node and gives it a value – 62181. This value is a port, where Node should wait for a debugger connection, 62181 by default (in my case). Previously Node-inspector connected to this port; right now WebStorm is connected to it. Respectively, it executes the needed interface. Now, if open the browser and go to this url,

    http://127.0.0.1:1337/echo?message=TEST

    Read More:  8 Best Blogs for Entrepreneurs: Start Business, Grow Professionally, or Change Your Life

    the system will stop. Here, in WebStorm I can open different thing, analyze variables, view urlParsed, etc.

    So, let us sum up the mentioned debugging methods in Node.js.

    1. The first way is to launch a node debug Node will immediately stop the script execution and move to a special mode of console debugging, where it will get a list of commands via help, control the script execution, enter the console mode through repl. It works, but it’s too simple.
    2. If you want to have a more convenient interface, use one debugging method in Chrome browser through Node-inspector or under IDE, whether it is possible. To make this type of debugging possible, launch Node with a special flag —debug or debug-brk. In this case, debug-brk will immediately move the script to a pause state. If Node is launched with these flags, it will give an access to the v8 built-in debugging mechanism. Respectively, v8 starts to listen to this port, 5858 by default. The debugger gets connected to it and can send commands controlling the execution process, receiving variables, etc. For Chrome debugging you can use Node-inspector as a debugger, which, from the one side, gets connected to the Node port and can talk to it and, from the other side, it shows a Chrome page and receives commands with its help. You can use other modern browsers instead of Chrome.
    3. Concerning IDE, we can say that everything depends on the very IDE and how everything’s placed in it. These things can be convenient or not. As for me, I believe the most trusted way is debugging with But you need to launch Node–inspector for it.

    You can find lesson’s code here .

    debugging

    The materials were borrowed from the following screencast

    We are looking forward to meeting you on our website blog.soshace.com

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Ivan Rastvorov
    • Website

    Related Posts

    Leveraging Crowdfunding to Successfully Fund Your Startup

    December 18, 2024

    Strategies for Enhancing Customer Retention in Startups

    December 17, 2024

    Conquering Imposter Syndrome: Empowering Startup Founders

    December 16, 2024
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Node.js November 2, 2020

    Node.js Lesson 9: Events, EventEmitter and Memory Leaks

    Hello everyone, today we are going to talk about events, what exactly are they. Then we will move on to understand what are EventEmitters and how to use them. We will also learn about memory leaks and learn about ways of dealing with it.

    Google I/O 2019: New JavaScript Features

    May 15, 2019

    JavaScript / Node.js Tools

    January 14, 2016

    Optimizing Recruitment: Best Practices for Employers and Candidates

    December 16, 2024

    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

    Effective Strategies for Managing Scope Creep in Projects

    JavaScript November 26, 2024

    Java Stream API

    Beginners October 30, 2020

    React Lesson 5: React Devtools and Reusable Open-Source Components

    JavaScript December 20, 2019

    Create Simple POS With React, Node and MongoDB #4: Optimize App and Setup Deployment Workflow

    JavaScript February 17, 2020

    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
    Remote Job

    How Deep Work Can Change Your Freelance Life

    JavaScript

    React Lesson 9: Homework Lesson 8

    JavaScript

    React and AJAX – The Art of Fetching Data in React

    Most Popular

    22. Чат Через Long-Polling. Чтение POST. Pt.2.

    Programming

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

    Java

    Understanding Python Decorators and How to Use Them Effectively

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

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