Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

NodeJS Console

NodeJS Console

The NodeJS console module provides a simple debugging console similar to the JavaScript console available in web browsers. These methods write to standard output or standard error and are useful for logging, debugging, and inspecting data.

Console MethodDescription
log()Prints standard output (stdout) with a newline.
error()Prints standard error (stderr) with a newline.
warn()Alias for error().
info()Alias for log().
dir(obj)Uses util.inspect() and prints a readable representation of an object.
time(label)Starts a timer that can be used to measure the duration of an operation.
timeEnd(label)Stops a timer started by time() and prints the elapsed time.
trace()Prints a stack trace showing the current call path.
assert(value, message)Throws an AssertionError when the condition is false.
table(data)Displays tabular data in a readable table format.

Console Example

console.js
console.log('Hello Tutorials Logic!');
console.error('Error');
console.warn('Warning');
console.info('Information');

console.time('timer');
for (let i = 0; i < 100000; i++) {}
console.timeEnd('timer');
Key Takeaways
  • Node.js provides a built-in console module for logging, debugging, and inspecting values.
  • console.log() writes to standard output, while console.error() writes to standard error.
  • console.warn() and console.info() are convenience aliases for warning and informational logs.
  • Use console.time() and console.timeEnd() to measure execution time.
  • console.dir() and console.table() help inspect objects and arrays in a readable format.
  • Console methods are helpful during development, but sensitive information should never be logged in production.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.