My notes from attending the filming of the Frontend Masters course Digging Into Node by Kyle Simpson.
The main takeaways for me were:
- becoming familiar with how stream processing works in Node code
- becoming familiar with core packages to use
- learning how to make a simple webserver without using Express
- learning how to spawn processes in Node to create parallelism for load tests against a server
I'm not sure when, if ever, I'll use this. If I ever have to do serious Node work, I may reference the video or these notes.
- JS is well-suited to high throughput / low latency tasks
- Kyle was attempting to write a server-side JavaScript engine with V8 before he heard of Node. He was excited when Node was released.
- The author of Node originally was writing a system in Ruby, but found he needed something like the JS event loop, so he switched to JS to get that for free.
- Node is well-suited to usage as a "middle end" system to bridge between frontend/backend
- Add
#!/usr/bin/env node
to top of your Node script file and make executable so you can run it from cmd line without referencingnode
- GZip compression was designed as a streaming algorithm
- Streams have events you can listen to, like "end" to know when a stream is done
- Wow
console.table()
is pretty cool for printing arrays of flat objects (e.g. any DB data) - Debugging in Chrome:
- Use GoogleChromeLabs/ndb or ...
- Open Chrome and navigate to this URL: chrome://inspect/#devices
- Launch a node script with
node --inspect <name of script file>
- Return to chrome and see a new row referencing the running script and an inspect link ... click it
- Go to the Sources tab and click
Pause on exceptions
and check the checkbox - When you hit an exception, debug!
- Production tips:
- Use "forever" or something like it to restart your node process if it dies
- single node process SSL
- loopback monitoring tools for node
- the Node org ships a production hardened version of Node.
- watch the FEM courses
There are sooo many packages available in the Node ecosystem. It's good to see what someone like Kyle uses..
path
: deal with file pathsfs
: deal with filesstream
: ability to process input and output in chunksspecifically theTransform
function,zlib
: streaming impl of gZip/Unzip compressionutil
:.promisify
takes something that requires callbacks and returns one that returns promiseshttp
: to create an HTTP serverchild_process
: spawning a process
minimist
: simple handling of command line params.yargs
if you need morecaf
: cancelable async flows, allows you to provisqlite3
: a decent databasenode-static-alias
: serve static filesnode-fetch
: just likefetch
in the browserexpress
: ubiquitous library for web-server apps