Node.js Lesson 7: Console Module

Node.js Lesson 7: Console Module

Console module which is by far the most commonly used module in Node.js JavaScript environment. We will learn all the powers we get with Console Module that helps us in development and debugging.

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.

node javascript programming developer web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Node.JS Developers | Skenix Infotech

We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.

The Ultimate Guide to Web Scraping With JavaScript and Node.js

We’re going to illustrate how to perform web scraping with JavaScript and Node.js. Learn how to use the Axios and Cheerio packages to extract data from a simple website. Learn how to use a headless browser, Puppeteer, to retrieve data from a dynamic website that loads content via JavaScript.

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

JavaScript Full Course - Beginner's Guide to JavaScript on Node.js

This complete 51-part JavaScript tutorial for beginners will teach you everything you need to know to get started with the JavaScript on Node.js. JavaScript Full Course - Beginner's Guide to JavaScript on Node.js