Learn

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.

Since console is a global module, its methods can be accessed from anywhere, and the require() function is not necessary.

Instructions

1.

Inside app.js, we have an array of pets, cleverly named petsArray.

Use 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.

2.

Next, using the console.table() method, print petsArray to the terminal as a table.

3.

Lastly, inside the console.assert() method, check if the length of petsArray is greater than 5.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?