One of the reasons that developers enjoy working with Node.js is that it's syntactically virtually identical to frontend JavaScript.
Let's take a look at some of the code we've already written.
Here is an example of JavaScript code:
document.getElementById('submit').onclick = event => {
event.preventDefault()
fetch('/data')
.then(res => res.text())
.then(response => alert(response))
.catch(err => console.error(err))
}
Now, let's take a look at some Node.js code that does something completely different, but with similar grammar, with dot notation, curly braces, and such. Here is an example of this:
const http = require('http')
http.createServer((request, response) => {
response.writeHead(200, {'Content-Type': 'text/plain'})
response.end('Hello World!')
}).listen(8080)
At first glance, these two code snippets may not look all that similar, so let's take...