Node.js | console.error() Function
The console.error() function from console class of Node.js is used to display an errror messages on the console. It prints to stderr with newline.
Syntax:
console.error([data][, ...args])
Parameter: This function can contains multiple parameters. The first parameter is used for the primary message and other parameters are used for substitution values.
Return Value: The function returns an error message.
Below programs demonstrates the working of console.error() function:
Program 1:
// Store number to variable num = 20 // Check condition if (num < 100) { console.log("Enter number greater then 100"); } else { console.error("correct choice"); } |
Output:
Enter number greater then 100
Program 2:
// Store number to variable x = 20; y = 50; // Check condition if (x > y) { console.error('%d is greater then %d', x, y); } else { console.error('%d is less then or equal to %d', x, y); } |
Output:
20 is less then or equal to 50
Recommended Posts:
- Nodejs | Automatic restart NodeJs server with nodemon
- Nodejs | DNS
- Nodejs | Jimp
- Nodejs | DNS | setServers()
- Web-Socket in NodeJS
- Dockerizing a simple Nodejs app
- Nodejs | Web Crawling using Cheerio
- Encrypting Data in NodeJS
- Difference between NodeJS and AngularJS
- Cowsay in Nodejs using Requests library
- NodeJs - Handling invalid routes
- Nodejs – Connect Mysql with Node app
- Signup Form Using Nodejs and MongoDB
- NodeJS | Building simple REST API in express
- Nodejs - Connect MongoDB with Node app using MongooseJS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


