Additional Concepts
Event Loops
It is what allows Node.js to perform non-blocking I/O operations
Despite the fact that Javascript is single threaded
By offloading operations to the system kernel whenever possible
It looks into the task queue and whenever call stack is empty, it pops the task from task queue and pushes it in call stack
Example
console.log('first')
setTimeout(() => {
console.log('second')
}, 0)
console.log('third')
// OUTPUTS
// first
// third
// secondPromises
Async/Await
Method 1
Method 2
Method 3
Events
Event Driven Programming is used heavily in NodeJS
Example 1
Example 2
Streams
Extends EventEmitter class
As file gets bigger and bigger, we should not read the whole file and store it in a variable
Types
Writeable
Readable
Duplex
Used to both read and write data sequentially
Transform
Data can be modified while writing or reading
Example 1
Write.js
Reading.js
Example 2
Last updated