Skip to content

Solutions for exercises from selected self-paced workshops in Node.

License

Notifications You must be signed in to change notification settings

sweeneyngo/learn-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

learn-node

Solutions for exercises from selected workshops in Node. Self-paced, focus on clarity over efficiency.

Targeted a select few based on what I wanted to learn. May do more workshops in the distant future.

Note: For promises, use Node's Argon (LTS v4.9.1). I recommend nvm use v4.9.1.

What is Node?

A simple I/O platform to write JavaScript. Many things constitute as I/O, such as:

  • Reading/writing files
  • Pushing notifications
  • Managing an API
  • Managing a Database
  • Caching
  • Resource buckets

It is async, or non-blocking. It supports callbacks, events, streams, and modules.

Callbacks are the core essence that powers asynchronicity. Typically, async/await is used in tandem.

Events act as pub/sub, and we connect callbacks to each. Events are many-to-many, so the same event can trigger multiple callbacks, and there can exist multiple events.

// For example,
client.on('eventOne', callbackOne);
client.on('eventOne', callbackTwo);
client.on('eventTwo', callbackThree);

Streams work exactly like in UNIX, using backpressure to throttle flow. In ohter words, it minimizes buffering data to chunks. It's also a countermeasure to callback hell.

const http = require('http');
const fs = require('fs');

// Without streams,
const server = http.createServer((req, res) => {
    fs.readFile(__dirname + '/data.txt', (err, data) => {
        res.end(data);
    });
});

// With streams,
const server = http.createServer((req, res) => {
    const stream = fs.createReadStream(__dirname + '/data.txt');
    stream.pipe(res);
});

server.listen(8000);

Modules have a similar philosophy to streams. They allow for separation of concerns with code. With Node, it opts for local package management similar to Python's virtual environment by default.

Sources

Resources for learning + building with Node.

About

Solutions for exercises from selected self-paced workshops in Node.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published