Before Node
Before Node, we only used JavaScript to build applications that run inside of a browser. Every browser has a JavaScript Engine that takes your JavaScript code and turns it into an executable form
- Microsoft Edge uses Chakra
- Firefox uses SpiderMonkey
- Chrome uses V8
- Safari uses JavaScriptCore
A JavaScript engine, at its core, consists of an interpreter and a runtime environment.
- JavaScript was (and still is considered) as an interpreted language. This means the JavaScript engine in a browser reads over the JavaScript code, interprets each line, and runs it.
- Modern browsers, however, use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run. The byte-codes are then executed using a JavaScript Runtime Environment.
- The runtime environment inside a browser provides global objects such as
window
anddocument
that enable JavaScript to interface with the browser and the webpage it is part of.
In 2009, Ryan Dahl took Google's v8 engine and embedded it in a C++ program and called that program Node.
Node uses Google's V8 to convert JavaScript into byte-codes but runs it outside of a browser.
In Node, we don’t have browser environment objects such as window
or the document
object. Instead, we have other objects that are not available in browsers, such as objects for working with the file system, network, operating system, etc.
If you are interested to learn more about the JavaScript Engine and how your code is executed, I recommend the following readings: