Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Tips

    Top 9 Web Components UI Libraries

    Consultation

    Best Service provides for Small Businesses

    Beginners

    Getting Started with React Native in 2020

    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 / Programming / 14. Node.js Lessons. Script Debugging pt 1.
    Programming

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

    bragin_paBy bragin_paSeptember 30, 2016Updated:October 5, 2019No Comments5 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    14. Node.js Lessons. Script Debugging pt 1.
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link

    558936827d369

    Our next lesson is devoted to Node.JS debugging. First of all, we will explore the simplest built-in debugger that is called by the node debug command. It looks just like that. Imagine, we’ve got the script:

    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);
    
        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");
    

    For example, we would like to stop server.js that is constantly malfunctioning, at a certain point to see its variables and what’s going on. That’s why we put debugger right here:

    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");
    

    And launch your script in a debugging mode: node debug server.js. You will need no modules for that purpose. The script initially is paused. As you can see, nothing happens. The bugging mode includes some commands, and right now we need one of them – cont. It will make the script continue its work. As we see, it did continue and even showed log in the end. Good job!

    Let us move now to our browser and go to url 127.0.0.1:1337 with this port. Once we’ve done this, the request event happens, a handler gets launched, and execution stops right at the debugger command. Now I can move to the repl console – a command execution mode – and, for example, clear up what urlParsed is or just launch something like:

    res.end(“Uahahaha!”) 

    Now look what’s happened with our browser. Great! It’s working.

    We should say, the built-in debugger that we’ve just explored is the simplest of the existing things. It is rarely used only in those cases, when more improved debugging ways do not work for some reason or when you don’t have time or will to launch them.

    Read More:  Getting started with Git Hooks using ghooks

    Node.JS-Debugging-Tools

    It is far more convenient to debug using the developer tool in Chrome. You will need the utility named Node- inspector:

    npm install -g node-inspector

    Install it globally. That’s all for our preparations. And now just a few words on what will happen next. Node.js has a special launching parameter – debug, and you can write a script right after it (–debug server.js). Whenever Node.js is launched with this parameter, it does not only launch server.js, it also starts to listen what’s going on in this port. Another program can connect to the port and give commands to Node.js concerning debugging – for example, to pause or continue the work, get a current value of some variable, etc. These commands are given in full compliance with a special protocol described in the supporting materials for v8. For example, the command

    {“seq”:117,”type”:”request”,”command”:”continue”}  

    means continue. While this one:

    “seq”:117,”type”:”request”,”command”:”evaluate”,”arguments”:{“expression”:”1+2″}}

    tells Node.js to calculate  1+2. Of course, we won’t write these commands manually, though we could do it. Instead, we use the Node-inspector utility that will send these commands by showing nice web interface to us.

    So, I leave Node.js launched and open a new console window, where I will launch the node-inspector. It is a web server you can connect to under the url, which is given by the server, and work with a debugger. It means, I will send commands to the Node-inspector web server, and it will translate them for Node, which listens to the debugging protocol using the v8 debugging language.

    So, let’s go to Node-inspector. The design reminds us of the built-in Chrome developing tools, but they are not those ones. Indeed, they look similar to each other because html styles were borrowed from the webkit engine. So, the interface looks quite alike. In fact, it’s just a web page the Node-inspector gives us.

    Read More:  An In-Depth Guide to Algorithms and Data Structures

    Using a separate window go to:

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

    The following has happened. Once I’d followed the url, a request handler function was launched. If Node.js had been launched without debugging flags, the debugger command would have been ignored, but it has worked in our case. v8 temporarily stopped JavaScript execution and sent this information to a Node-inspector, which had been connected to Node via the port: 5858. Node-inspector received it and, using a web-soсkеt protocol, which we will explore further, sent it to the browser – to browser JavaScript. Here the web interface reacted this action and gave me a pause. The same interface requested data on the stop, which I can use. At the same time, Node-inspector is responsible for translating my actions into commands for the v8 debugger. I can even use the console. If I want to respond the request, I can do the same thing that I’ve done to a built-in debugger – to call a method in a current window.

    Everything is quite handy. You are recommended to use it. The only thing you should take into consideration is that we are working with a connection chain. Entering this url to the Node-inspector we connect from client browser JavaScript to server Node-inspector, the latter connects to Node.js and sometimes one of these connections gets broken. Respectively, debugging doesn’t work. In this case you can go to the debugging page again and if it hasn’t been effective, restart your Node-inspector. If this measure does not help you, too, go ahead and re-launch the whole chain: Node, Node-inspector and open the browser page once again. It will definitely work in the end.

    tumblr_ng6oke7J1k1sxr61eo1_1280

    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
    bragin_pa

      Related Posts

      Mastering REST APIs: Essential Techniques for Programmers

      December 18, 2024

      Crafting Interactive User Interfaces Using JavaScript Techniques

      December 17, 2024

      Effective Strategies for Utilizing Frameworks in Web Development

      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
      Interview April 12, 2019

      Top 15 Node.js Interview Questions | Theory and Practice for 2019

      Node.js, a JavaScript run-time environment used by countless remote professionals today, is a hot topic in the web development sphere. To ace your next technical interview, check these Node.js interview questions out!

      Enhancing Recruitment: The Crucial Role of Diversity and Inclusion

      December 16, 2024

      Agile Software Development, Scrum part 3

      August 12, 2016

      React Lesson 6: CSS and Animation

      January 4, 2020

      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

      Analyzing Leadership Styles and Their Influence on Project Success

      JavaScript November 25, 2024

      Understanding Flutter Bloc Pattern

      Flutter September 18, 2019

      How To Secure Python Web App Using Bandit

      Programming February 13, 2021

      Build Real-World React Native App #3: Home Screen With React Native Paper

      JavaScript November 23, 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
      JavaScript

      Top React JS Interview Questions

      SEO & Analytics

      Effective Data Visualization Techniques for SEO Reporting

      JavaScript

      Create simple POS with React.js, Node.js, and MongoDB #9: CRUD Branch

      Most Popular

      Real-Time Subscriptions with Vue and GraphQL

      GraphQL

      Create a simple POS with React, Node and MongoDB #1: Register and Login with JWT

      JavaScript

      Стиль кода

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

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