Browser JavaScript and Node overlap:
-
Browser JavaScript
- window
- document
- localStorage
-
Node
- fs
- path
- http
-
Both
- Browser JS and Node JS are mostly the same with a few exceptions - mostly environment dependent
- You can write one module (file) and use it on the server and in the browser, like a date formatter or input validator
-
Event Loop
- JS runs in one main thread called the Event Loop
- The event loop delegates certain slow tasks to a pool of worker threads. When the worker threads finish, they give the results of their work back to the main thread.
- The event loop moves onto other tasks after it gives work to a worker thread. It does not wait. This helps make node fast because it is asyncronous.
-
Node isn't a language, it's a runtime called V8 for JavaScript. This just means we can run JS outside of a browser, like on a server.
-
It uses a module system called CommonJS. Or you can use an alternative called ES Modules.
-
With Node, even version numbers are Long-Term Support (LTS) versions.
-
NVM: Unofficial version manager to manage the version of Node used per project
-
NPM: Node Package Manager, install third-party dependencies (modules) using
npm install <package>
-
Tooling: Node might be known as something you'd make servers with, but it's equally useful for development tooling
-
Tools like Webpack and rollup can bundle ES Modules in a way that makes them ready for the browser