Node.js Flashcards
What is Node.js?
A runtime environment used for executing JavaScript code on the SERVER-SIDE, instead of in the browser.
What is an engine?
An engine is what processes our code and makes it do something in the browser.
The engine is what makes it possible for a computer to understand human readable code such as JavaScript.
Google Chrome = V8 JavaScript engine; Mozilla Firefox = SpiderMonkey;
Apple Safari = JavaScriptCore;
The engine also decides how it processes our code, e.g compiles, interprets or JIT’s our code
What relevance does ECMAScript (ES) have to an engine?
ECMAScript is the standard regulations that the browser engines comply with so they know how to interpret and execute your code.
JavaScript is an implementation of the ECMAScript standard.
What is an environment?
The browser is what we call an environment.
This is where our code is being executed, and USUALLY the engine is a part of the browser environment. (Node.js does not do this!)
What engine does Node.js use?
Both your browser, JavaScript & Node.js run on the Chrome V8 JavaScript runtime engine.
This engine takes your JavaScript code and converts it into a faster machine code.
Machine code is low-level code which the computer can run without needing to first interpret it.
What is a runtime environment?
A runtime environment is the where the code is processed (by the engine) & executed.
So with Node.js:
- The server = environment
- Runtime = when the code is running
What is meant by Asynchronous API?
All APIs of Node.js library are aynchronous that is non-blocking.
A Node.js based server never waits for a API to return data.
The server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.
What are the benefits of using Node.js
Aynchronous and Event Driven
Very Fast
- Google Chrome’s V8 JavaScript Engine is the fastest at interpreting JS code, which = super fast code execution
Single Threaded but highly Scalable
No Buffering
- data is outputted in chunks
What is an error-first callback?
Error-first callbacks are used to pass errors and data.
The first argument is always an error object that the programmer has to check if something went wrong.
Additional arguments are used to pass data.
E.G.
fs.readFile(filePath, function(err, data) { if (err) { // handle the error } // use the data object })
Different between Node & AJAX
???
What are Event Listeners?
Node.js has built in event’s and built in event listeners. Node.js also provides functionality to create Custom events and Custom Event listeners.
They are similar to call back functions, but are associated with some event.
E.G. when a server listens to http request on a given port, an event will be generated to specify the HTTP server has received it & will invoke corresponding event listener.