🔄 Asynchronous vs Synchronous
- Asynchronous: More than one process running simultaneously.
- Synchronous: One process executing at a time.
- JavaScript is synchronous by default, while Node.js is asynchronous.
⚙️ libuv and Event Loop
libuv
is the library that includes the event loop.
- The event loop loops over a queue of events, then uses V8 as a callback processor.
🚫 Non-blocking I/O
- Non-blocking means performing tasks without stopping the entire program.
🧠 Buffers
- A Buffer is a temporary holding spot for data that moves data from one place to another.
- Buffers can store, encode, and manipulate binary data.
const buf = Buffer.from('Hello World', 'utf-8');
console.log(buf.toString());
console.log(buf.toJSON());
console.log(buf[2]);
buf.write('h');
console.log(buf.toString());
🌊 Streams
- A Stream is a sequence of data made available over time (e.g., video streaming).
- Buffers and Streams can be combined to collect full data before making it available (e.g., like films).
📚 ES6 and Buffers
- New ES6 syntax in JavaScript supports Buffers unlike older versions.
📂 File System (Sync)