- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
NodeJS - console.group() Method
The Node.js console.group() method of node.js will return the given information in the method as a grouped format. It typically used to group the query results by one or more specified columns. You can use this method to aggregate data and perform calculations on groups such as totals, Averages and, Counts, etc. It can also be used to sort the output of grouped records in ascending or descending order.
A group contains a proper heading and below the heading, there will be some proper information or messages. So, the message which we are passing inside the console.group() method will be the group heading. And inside the group, we can write messages by using the console.log() function of node.js.
Syntax
Following is the syntax of the Node.js console.group() method −
console.group([label)];]);
Parameters
label − This is the label for the group. This will act as a heading for the group which is we are grouping on the console. This is not a mandatory parameter; we can also use this method without a parameter (label).
Return value
This method will group the contents on the console with the label if it is passed. Else it will group without a label.
Example
The Node.js console.group() method of node.js will accept only one label parameter(optional parameter).
Note − By default, the groups will be expanded in the console.
In the example,
We are creating a group with console.group() and passing a parameter(label). This label will act as a group heading.
Then we are writing some messages inside the group by using the console.log() function.
Then we are ending the group by using the Node.js console.groupEnd() method.
console.group("GROUP 1"); console.log("Knock knock....first message in Group 1"); console.log("Knock knock....second message in Group 1") console.log("Done with the messages, closing the group now"); console.groupEnd();
Output
As we can see in the output from the figure below, we have created a group with a label passing to the console.group() method, written some messages, and closed the group.
GROUP 1 Knock knock....first message in Group 1 Knock knock....second message in Group 1 Done with the messages, closing the group now
To understand better execute the above code in the browser's console. Following is the output of the above program in the browser's console.
Example
In the example, We are creating nested groups by calling a group inside a group, and then we close the groups accordingly.
console.group("GROUP 1"); console.log("Knock knock....first message in Group 1"); console.log("Knock knock....second message in Group 1") console.log("Done with the messages, closing the group now"); console.group("Nested group 1"); console.log("Knock knock....first message in Nested group 1"); console.log("Knock knock....second message in Nested group 1") console.log("Now we are entering into another group inside nested group"); console.group("inner nested group"); console.log("OOPS! no messages here."); console.groupEnd(); console.log("inner nested group ended"); console.groupEnd(); console.log("Nested group ended"); console.groupEnd(); console.log("GROUP 1 ended");
Output
As we can see in the output below, we created the main group, then a sub-group, and a group inside the subgroup.
GROUP 1 Knock knock....first message in Group 1 Knock knock....second message in Group 1 Done with the messages, closing the group now Nested group 1 Knock knock....first message in Nested group 1 Knock knock....second message in Nested group 1 Now we are entering into another group inside nested group inner nested group OOPS! no messages here. inner nested group ended Nested group ended GROUP 1 ended
To understand better execute the above code in the browser's console. Following is the output, if we execute it in the browser's console.
To Continue Learning Please Login
Login with Google