The great thing about Node.js is that you already know how to write it! Take this for example:
JavaScript |
Node.js |
console.log("Hello!") |
console.log("Hello!") |
That's not a trick: it's identical. Node.js is syntactically almost identical to browser-based JavaScript, right down to the fight between ES5 and ES6, as we've discussed previously. In my experience, there is still a preponderance of ES5-style code in use with Node.js, so you will see code with var instead of let or const, as well as a healthy use of semicolons. You can review Chapter 3, Nitty-Gritty Grammar for more information on these distinctions.
In our guessing game example, we see one thing that is new to us – the first line:
const readline = require('readline')
Node.js is a modular system, which means that not all parts of the language will be brought in at once. Rather, modules will be included when the require() statement is...