Additional Concepts

Event Loops

Example

console.log('first')
setTimeout(() => {
	console.log('second')
}, 0)
console.log('third')

// OUTPUTS
// first
// third
// second

Promises


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