Final Review
Last updated
Was this helpful?
Last updated
Was this helpful?
Browser needs to respond to events all the time -> necessity for asynchronous programming.
Data requests are typically handled within a callback function, which responds with data once it is processed.
In an asychronous environment, a single process thread runs all the time, but it may, for event-driven reasons (and that is the key), switch from one function to another. When an event happens, and when the currently running process hits a point at which it must wait for another event, the javascript core then scans its list of events and delivers the next one, in a (formally) indeterminate (but probably deterministic) order, to the event manager.
Javascript is not multithreaded - there are not different threads handling many different things. Instead, js is designed to handle on thing at a time, but also move on if nothing is happening to begin with.
Node is asynchronous, v8 JS is synchronous (one line at a time).
Asynchronous goes through a process called non-blocking (libuv) where, it doesnt wait for a function to finish when it could potentially move on to the next line of code.
db is an object that opens a database file. If the file does not exist, it is created.
The data is trying to obtain the column of 'males' within the db table.
The callback function is function(err, row){ .. }
Gets run once the request is actually processed.
The code should run on the server because we are processing database files.
Body is the data of the api response. The function is not within the callback function, so it gets executed immediately before the callback function has time to process the response.
The server waits to handle api, db, sql, or http responses
API and DB are handled within callback functions - since we have to wait back for responses.
Browser http requests are handled within index.js, where a function handler (request,response)
responds to queries from the user.
HTTP is a protocall, or more simply put, a set of (arbitrary) rules that client and server follow when they communicate.
The server works in different ways, but in general XML requests are directly linked with browser queries to our own server.
Server and API requests that are not on your own server are used with nodes request function.
Node handles all events asynchronously.
Event handlers process work through a queue. What comes in first, is will be handled first, and any other events will be stacked on top.
The process:
Starts with user/client on the browser
Loads static webpage files from the files from your ./public directory
Both you the browser and server have an IP. A socket is created when connecting these two IP's.
HTTP is actually sent through TCP/IP through this socket with pieces or packets. HTTP contains head(meta: status, length, type of data) and body(data) information about the thing we will send.
Your port number is used when the browser requests information, and will know what file to access it from.
Hold a static server when we actually want to hold files from our computer. For example, d3. Deals with same origin policy.
The same-origin policy restricts how a document or script loaded from one origin can interact with a resource from another origin. It is a critical security mechanism for isolating potentially malicious documents.
The important bit here is that it is specific to your address/address and that the server will send over requested information to your machine.
Contains the URL (request.url)
Used with queries that can parse these urls
urlStr = “hello.html?dog=rover&cat=max”
urlObj.pathname = “hello.html”
urlObj.search = “?dog=rover&cat=max”
Query server refers to file queries.js in assignment 5, and is meant to respond to different queries from the user. For example, button actions can request for some particular data. Or a drop down menu can ask for some unique data that is sent off to queries, where it then packages information from your static server . var reqURL = "http://45.55.29.158:8847/query?districts=demVoters";
Our callback functions are usually defined within a function that specifies an XML request.
The closure: interior function also contain the variables and contents of the function it is wrapped around.
XML requests are used to respond to queries in the browser from the user.
Difference between XMLHttpRequest (makeRequest), and request():
XML is used to send HTTP or HTTPS requests to a web server and load the server response data back into the script.
request takes in a full string URL, and is used to get data from other servers.
AJAX = Asynchronous JS and XML invokes the sending and receiving of objects to your browser from the server. The slide is trying to emphasize that your browser wont just load information off directly from the url. Instead, the browser has to communicate with the server and listen to requests with XML requests.
There is always the assumption that malicious malaware is running on the browser. Same orgin enforces the idea that there are is one way channel between browser and server.
Most browsers implement the Same Origin Policy – data can usually only be downloaded from the same server the Web page came from (but there are a lot of exceptions)
d3 takes visual objects applies properties to them like .data, height, background-color, class, etc
The basic idea behind a gradient is that there is a start and ending color, everything in between these two colors is some fraction in between.
Columns defined by {name} {TYPE}
Returns a list of objects from specified column that follow some condition.
Row selection *