What is Node?#
📝 This lesson's quiz can be found - here.
🗒️ Solutions for this lesson's quiz can be found - here.
📖 This lesson's lecture slides can be found - here.
Node was originally released in 2009 by Ryan Dahl as a response to how slow web servers were at the time. This is because most web servers would block the I/O (Input/Output) task (e.g. reading from the file system or accessing the network) which will lower throughput. Node changed this model by making all I/O tasks non-blocking and asynchronous. Non-blocking, for example, just means a request from another interaction can be processed without waiting for the prior interaction request to finish. This allowed web servers to serve countless requests concurrently.
Here's an example taken from the main Node website in comparing code between the synchronous blocking state and the asynchronous non-blocking state.
This example covers the use of the Node File System (
fs module) which allows us to work with the file system in our computer.
const fs = require("fs");
const data = fs.readFileSync("/file.md");
The file system module is included by stating
readFileSync() method is used to read files on the computer with which we've stated we want to read the markdown file named
readFileSync() method is synchronous so the
moreWork() function will only run after the entire file is read in the process. Since the
readFileSync() method blocks
moreWork() from running, this is an example of synchronous blocking code.