The console Object in Node.js
The console object in Node.js is a global object used to print messages to the standard output (stdout) and standard error (stderr). It is similar to the browser's console but provides more utilities for server-side debugging.
console Methods
-
console.log()– Prints normal messages to stdout.console.log("Server started"); -
console.error()– Prints error messages to stderr.console.error("Something went wrong!"); -
console.warn()– Prints warning messages.console.warn("This is a warning"); -
console.info()– Alias forconsole.log(). -
console.table()– Displays tabular data in table format.console.table([{ name: "Alice", age: 25 }, { name: "Bob", age: 30 }]); -
console.time()andconsole.timeEnd()– Measures execution time.console.time("process"); // some code console.timeEnd("process"); -
console.assert()– Logs a message if an assertion fails.console.assert(2 + 2 === 5, "Math is broken"); -
console.clear()– Clears the console (in supported terminals).
console methods are synchronous and best used for debugging, not production logging.


