Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Programming

    23. Node.js Lessons. Domains, asynchronous try.. catch. Part 2.

    Job

    Imposter Syndrome in Web Development: Understand It, Overcome It

    Programming

    19. Node.js Lessons. Safe Way to a FS File and Path

    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 / JavaScript / Node.js / Node.js Lessons / Node.js Lesson 7: Console Module
    Node.js

    Node.js Lesson 7: Console Module

    Mohammad Shad MirzaBy Mohammad Shad MirzaOctober 9, 2020Updated:October 9, 2020No Comments6 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Node.js Lesson 7: Console Module
    Node.js Lesson 7: Console Module
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Node.js Lesson 7: Console Module
    Node.js Lesson 7: Console Module

    Hello everyone! In the last lesson, we learned about the util module. This lesson will talk about another module which is by far the most commonly used module in node.js javascript environment. We will learn all the powers we get with this mighty module that helps us in development and debugging. Let’s start

    What is the console

    console provides a way to print/output certain messages on to the console. It’s very useful for testing and debugging. console is a globally present module that you can use anywhere in the project without requiring it. It means something like require(‘console ‘) is not needed to use it in any file. The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. It provides us a bunch of functions that we can use to print text. Example usage:

    console.log("This is a message to print");
    
    // This is a message to print

    It uses util.inspect and util.format internally. You can use this to print strings, arrays, objects, or any variable you like. It also supports string substitution just like util.format we studied in the previous lesson. Example:

    console.log("2 + 2 equals %d", 4);
    
    // 2 + 2 equals 4

    Other substitution strings are %o for an object, %d for integer, %f for floating-point value, and even %c for CSS styles. Example:

    console.log("%c this is red color log", "color: red");
    
    // prints "this is red color" log but in red color

    Of course, it doesn’t have only .log() function. It does provide us a lot of helpful functions in accordance with the message we want to print. Example console.error() for errors, console.table() for printing tables, etc. Let’s look at all of the types in detail.

    Types of functions in the console

    1. console.log

    We already read about this method in the examples above. This is most commonly used among all the functions to print a normal stream of the message. The first parameter is string message and the next parament can include multiple arguments for substitution.

    console.log("%d + %d is equal to %d", 2, 5, 7);
    
    // 2 + 5 is equal to 7

    2. console.error

    We usually have two types of message streams. Apart from the normal stream, we have an error stream and that’s where console.error comes handy. The usage is pretty similar to console.log but it is used to log errors mainly.

    console.error('error', 404);
    
    // error 404

    3. console.table

    This is particularly helpful when you are working with objects or tabular data with some kind of relationship. The first argument is tabular data and the second argument is property. Let us see an example:

    console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }]);
    
    This logs:
    
    | (index) | a   | b   |
    |---------|-----|-----|
    |    0    |  1  | 'Y' |
    |    1    | 'Z' |  2  |
    

    The second argument can be used to include/exclude properties:

    console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ['b']);
    
    This logs:
    | (index) | b   |
    |---------|-----|
    |    0    | 'Y' |
    |    1    |  2  |

    4. console.dir

    Consider this as a sibling to console.log which takes an object and logs object properties instead of a string. console.log logs (toString()) representation of object if passed, whereas console.dir recognizes that it’s an object and treats it like that. Example:

    console.dir([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }]);
    
    // [ { a: 1, b: 'Y' }, { a: 'Z', b: 2 } ]

    5. console.assert

    This checks if the value passed is truthy. The first argument takes a value and the second takes a message to log. This message is logged only when the value is not true. The output message always starts with ‘Assertion failed’ and it provides the formating using util.format.

    console.assert(true, 'truthy value');
    // logs nothing
    
    console.assert(false, 'whoopsy, this is false');
    // Assertion failed: whoopsy, this is false

    6. console.count

    This takes a label as the first argument and logged the number of times it is called. It maintains an internal counter and associates it with the label passed. The default label is “default” if none passed.

    console.count();
    console.count();
    console.count();
    
    console.count('wow');
    console.count('wow');
    
    // default: 1
    // default: 2
    // default: 3
    // wow: 1
    // wow: 2

    7. console.countReset

    This function comes along with the console.count which we just read above. It clears the internal counter based on the label passed. When no label is passed, it will clear the default counter.

    console.count('wow');
    console.count('wow');
    console.count('wow');
    
    console.countReset('wow); //reset counter
    console.count('wow');
    
    console.count('wow');
    
    // wow: 1
    // wow: 2
    // wow: 3
    
    // wow: 1
    // wow: 2

    8. console.time & console.timeEnd

    These two methods come very handy when you have to know how much time it takes to run a certain function/task. Simply add console.time() before the task starts and console.timeEnd() after the task ends. This will print out the time it took to execute that particular tasks.
    They also take a label as the first argument and associate the timer with it. You can use these labels to log multiple time logs but remember that they should be unique. .time() starts the timer and .timeEnd() ends the timer. They both should be used together. Example:

    // timer starts
    console.time();
    
    // running a loop to mimic a long task
    let a = 0;
    while(a < 100000){
        a++;
    }
    
    // timer stops
    console.timeEnd();
    
    // default: 1.843ms

    9. console.timeLog

    This also works with the above two methods but is optional. You can use this to log elapsed time after the timer starts.

    // example for Nodejs docs
    
    console.time('process');
    const value = expensiveProcess1(); // Returns 42
    console.timeLog('process', value);
    // Prints "process: 365.227ms 42".
    doExpensiveProcess2(value);
    console.timeEnd('process');
    

    10. console.debug

    The console.debug() function is an alias for console.log(). Although they can be used interchangeably, it is preferred to use console.log.

    11. console.clear

    This simply clears old logs on the console. If some logs are present, it will clear them. Otherwise, this function does nothing.

    console.count();
    console.count();
    console.count();
    
    console.clear();
    
    // logs nothing

    12. console.trace

    Logs the stack trace and helps in debugging.

    console.trace('What happened when I logged this message');
    
    // Trace: What happened when I logged this message
    //     at Object.<anonymous> (/Users/mdshadmirza/personal/BlogsByShad/test.js:33:9)
    //     at Module._compile (internal/modules/cjs/loader.js:1201:30)
    //     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)
    //     at Module.load (internal/modules/cjs/loader.js:1050:32)
    //     at Function.Module._load (internal/modules/cjs/loader.js:938:14)
    //     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    //     at internal/main/run_main_module.js:17:47

    13. console.warn

    The console.warn() function is an alias for console.error().

    Read More:  5 Essential SEO Tips for Web Developers

    Takeaways

    • the console is one of the most helpful modules that you will need more often
    • console.log and console.error should be used for the normal stream and error stream of messages respectively.
    • console.table help us log tables in a beautiful format and thus helps us in debugging.

    I hope this was helpful for you in understanding the console module better. You can find this lesson coding in our repository.

    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

    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

    Comments are closed.

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

    Node.js Lesson 1: Introduction and Modules

    Hello everyone, this is the first lesson of the Nodejs course and we are going to cover the basics of Nodejs. We will also understand Modules in Nodejs and create one ourselves. Let’s start.

    Navigating Remote Project Management Challenges: Best Practices

    November 30, 2024

    Уроки React . Урок 8

    September 30, 2016

    React Lesson 11. Pt.1: Normalize Comments with Immutable.js

    March 20, 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

    Interview With Oleg – Soshace Team

    Interview December 8, 2016

    The Impact of Social Proof on Thought Leadership Marketing

    Content & Leadership August 27, 2025

    Basic Principles and Rules of Our Team

    JavaScript January 19, 2016

    How to build a full stack serverless application with React and Amplify

    JavaScript May 5, 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
    Programming

    3. Уроки Node.js. Менеджер пакетов для Node.js

    Interview

    28 Sample Interview Questions for JavaScript Developers | Theory and Practice

    Job

    The Best Work Tools for Remote Teams — Part 2: Team Communication

    Most Popular

    Amazon S3 Cloud Storage Proxying Through NodeJS from Angular Frontend Securely

    Programming

    Programming Patterns. Introduction

    Programming

    JavaScript find() and filter() Array Iteration Methods Made Easy

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

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