Node JS Flashcards
What is Node.JS ?
Node.js uses an event-driven, non-blocking I/O model .
It is a runtime environment which means its self-encapsulated
It is single threaded with an Event Loop
It is just a terminal for background scripting (pure logic, no UI, no CSS, no DOM )
Javascript needs to work with C++ so we can write JS code to control C++ built features that allow control of our computer’s internal features.
JS -> Node -> Computer Feature (e.g. network, file system)
What is LibUV ?
A library that helps Node.js to do I/O operations with OS threads to avoid blocking the main thread
What is the Event Loop?
Event Loop determines what function/code to run next from the queues by repeatedly checking each queue.
What are the Six Queues/Phases and what builds it?
All the queues are built by Node C++
Timers
callback Queue
Idle
I/O Callback
Microtask
Check Queue
What 3 Languages are used to load a web app ?
HTML - things/elements
CSS - decorate/ prettify
Javascript - logic and interaction
Where does Data and Code come from?
Server ( basically another computer) that is connected to the internet always on and ready to receive a message
These messages specifically request data and code and the server decides what do I want to send back
What is basic explanation of how Node.JS works ?
User computer sends inbound message to computer’s internal features.
To access it, we need to use Node C++ features
We will write Javascript code to affect Node C++ features which then connect us to Computer’s internal features
What is the 3 things that Javascript does in this situation?
- Saves Data and Functionality (Code)
- Uses that data by running functionality (code) on it
- Js has a ton of built-in label that trigger Node features that are built in C++ to use our computer’s internals
What does HTTP mean and what does it feature do in NODE?
Hypertext Transfer Protocol
we use HTTP feature of Node to set up an open socket
What is socket ?
open channel for data to go in and out of a place over the Internet
How do we Call Methods in Node?
Node auto-runs the code (function) for us when a request arrives from a user
we have to rely on Node to trigger Js code to run
What are the steps to creating a server behind the scenes?
User Computer sends inbound message to Computer’s Internal Features and LibUV connects to NODE
Node will set up feature to access computer background internal features (e.g. open a socket) and Auto Run the doOnIncoming code and throw into Javascript
The Inbound message will trigger Node to create two auto created Javascript objects
1. 1st object will be able to receive incoming relevant data like taking URL from inbound message 2. 2nd object will have many functions that allow access to Node (e.g End, Write func) . It is labeled functionsToSetOutGoingData
Javascript will be triggered to run what Node gave it with the 2 objects passed in arguments in JS function and it will return data to the 2nd object for the outbound message.
JS will create server object that has function Listen so we can edit background C++ features like edit port number
We will rely on libUV to grab the outbound message from Node and send to Computer’s Internal Features which is then sent back to User Computer in readable format
What does Require Function do?
This function allows us to access each of Node C++ features independently
const http = require( ‘ http’ )
What is Error Handling like in Node?
Node will automatically send out the appropriate Event emitter depending on what it gets from the computer internals (http message or error)
If happy nicely formatted
REQUEST then auto run a function
Server.on(‘request’, doOnIncoming )
If corrupted
clientError then auto run a specific function
Server.on(‘clientError’, doOnError)
What is JSON?
JSON is a javascript-ready data format
Its just a string of characters
Easy way to take object to workable javascript format