One of the most commonly used Node.js core modules is the
console module. In Node.js, the terminal is used to send and receive text feedback to and from a program, often for debugging purposes. This may sound familiar to how we use the console in the web browser. That’s because in Node.js, the built-in
console module exports a global
console object that gives the terminal similar functionality. The
console object provides many of the same familiar methods such as:
.log()— to print messages to the terminal.
.assert()— to print a message to the terminal if the value is falsy.
.table()— to print out a table in the terminal from an object or array.
console is a global module, its methods can be accessed from anywhere, and the
require() function is not necessary.
Inside app.js, we have an array of pets, cleverly named
console.log() to print
petsArray to the terminal.
For these checkpoints, we’ll check the program with
node app.js behind the scenes when you press the Run button.
Next, using the
console.table() method, print
petsArray to the terminal as a table.
Lastly, inside the
console.assert() method, check if the length of petsArray is greater than 5.