Note: This was a vague, a-priori outline. We went over some of this during the talk.
JavaScript is just a language. Not inherently useful.
Host environment provides access to the outside world through APIs.
Browser provides APIs for the web. Sandboxed for security. Specs for interoperability.
Node.js offers input and output APIs for file system access (fs
) and networking (net
). Runs with full user privileges; caveat emptor.
The mechanism in Node.js to access all these APIs is the super nifty require()
function.
But wait, there's more! require()
also loads JavaScript and JSON files in relative paths or the special node_modules
folder. This is how we can structure large apps into multiple, smaller files, or spin-off parts into standalone packages for re-use across multiple apps.
This is where NPM comes in: handling the chaos of dependency management.
Let's refactor the reusable code in our app into a dependency by publishing it to the NPM registry.