The easiest way to install Node.js is to use the installers provided for you at https://nodejs.org. These packages will guide you through the installation of Node.js on your system. Be sure to also install npm, Node's package manager. You can refer to Chapter 3, Nitty-Gritty Grammar, for more details on installation.
Let's give it a go:
- Open a Terminal window.
- Type node. You will see a simple > to indicate that Node.js is running.
- Type console.log("Hi!") and hit Enter.
It's really as simple as that! Exit the command prompt either by hitting Ctrl + C twice or typing .exit.
So, that's fairly basic. Let's do something a bit more interesting. Here's the contents of chapter-11/guessing-game/guessing-game.js:
const readline = require('readline')
const randomNumber = Math.ceil(Math.random() * 10)
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
askQuestion()
function askQuestion() ...