Week 3 - Node.js, Express, MongoDB
What is a dependency
Something that needs to happen before a task can be executed.
What is synchronous and asynchronous programming, and the difference between them?
Synchronous programming means starting one task and not moving on to another (independent) task until the first one is complete. Asynchronous programming is the allotting of time to a specific task, then moving on to another (independent) task if the first is not yet complete, and so on in a loop until all tasks are complete.
what is the npm?
The node package manager. A JavaScript runtime environment where JavaScript developers can test and debug JavaScript applications. Written my many other developers to do menial tasks so we don't have to.
What is passed into the [, options] parameter?
The options allow you to define (1) encoding - default null, but can be set to utf-8 (2) flag - default 'r' for reading, but can be set to 'a' for appending
What is the 'path' module in Node.js?
The path module allows you to work with files on your computer. it can handle the navigating, loading, reading, and updating file paths in your computers storage.
What does cashe mean?
The storage of recently used information so that it can be easily retrieved later. This allows computers to run more efficiently.
What are the two default internet ports, and what is the difference between them?
The two default port numbers for internet traffic are 80 and 443. 80 is for unsecured data using http, and 443 using https
What are single page applications?
These are web applications the user interacts with that dynamically update the same webpage, instead of loading separate pages from the server.
What are CRUD operations
These refer to the four (4) major functions performed in most applications, databases, and interfaces
What are the HTTP "verbs"; and what "English" equivalent actions do they correspond to?
These verbs are the 7 actions that can be performed with an HTTP request, or the 7 types of "calls" we can make to an HTTP server. POST = "create" GET = "read" PUT = "update" DELETE = "delete" *crud operations (less used) PATCH, OPTIONS, HEAD
What does the following code snippet mean? app.METHOD(PATH, HANDLER)
This generalizes routing for all HTTP requests. the .method represents any of the 7 HTTP actions that an HTTP server can serve, 'path' represents the resource location, and 'handler' represents the function defining the action to take when this type of request is made.
What does the "module.exports" command do?
This method allows you to make JavaScript functions in one module (or file) available in other modules (or files). We place this command after our defined functions and pass the functions we want exported into the module.exports command... To complete the process, other files can import this module using the 'require()' method
What does the DELETE action do
This method deletes a resource
What does the POST action do
This method returns a CREATed resource.
What does the PUT action do
This method returns an updated resource (or a newly created one if one did not exist before).
what does the .createServer() method do?
This method turns your computer into a server. The function passed into this method will execute when someone tries to access the computer on our given port.
What is a requests' URI? and what does it stand for?
URI - uniform resource identifier (a.k.a. URL). A URI describes to the server what the client wants... while a URL (uniform resource locator) tells the server where to find what the client wants
What is data binding in web development
the ability to attach data to templates and create custom pages. Taking data given by the client (through forms or otherwise) and using that data to create/update webpage. In nunjucks, this is the {{data}} call
What does the GET action do
this method requests data from a resource (another browser or a web server).
Write the syntax that would create a server.
var http = require('http'); var requestHandler = function(request, response){ response.end('hello node server!'); } var server = http.createServer(requestHandler); server.listen(9000,()=>{ console.log('server is alive'); });
Write the syntax for formulating a server response.
var requestHandler = function(request, response){}
What do the import and export keywords do?
when we use these, order of requirements don't matter
Define a server
Made up of CPU, RAM, Storage, code (software). A server is different from a computer only by its software. A server has a protocol (HTTP), a port, a handler (for requests, phone calls, messages), request and a response (unique to HTTP)
What are the three types of storage?
1. Browser cashe - elements of pages that your browser stores so it doesn't have to keep downloading it every time you visit a website. theses elements are stored on your hard drive until manually deleted. 2. Session storage - data is stored until the browser tab is closed 3. Local storage - will not be deleted after the browser is closed. It exists indefinitely unless the user deletes them in their browser settings
What three (3) things do all requests have
1. URI - uniform resource identifier (a name) 2. head - headers, meta data about the information you are calling 3. body - information for the server on your request, routing data
What is a callback function
A function that is passed into another function, and is automatically called after the main function is complete. ---------------great example on stack overflow-------------------------- // A function which accepts another function as an argument // (and will automatically invoke that function when it completes - note that there is no explicit call to callbackFunction) funct printANumber(int number, funct callbackFunction) { printout("The number you provided is: " + number); } // a function which we will use in a driver function as a callback function funct printFinishMessage() { printout("I have finished printing numbers."); } // Driver method funct event() { printANumber(6, printFinishMessage); } https://stackoverflow.com/questions/824234/what-is-a-callback-function#7549753
What is a protocol?
A protocol is a set of rules that define a format of communication between two systems. HTTP defines the format for communication between two web BROWSERS
What is a query string?
A query string is a part of a requests' URL that gives additional information for the server to use (for processing in handler functions for different requests). Typical URL containing a query string is as follows: http://example.com/over/there?name=ferret When a server receives a request for such a page, it may run a program, passing the query string, which in this case is, name=ferret unchanged, to the program. The question mark is used as a separator, and is not part of the query string.
What is method chaining?
A syntactic strategy of "chaining" method calls one after another, so that the return of the first method is an object that the second method can perform its action to, and so on. app.route('/').get().post().put().delete()
What is the difference between a port and an IP ?
An IP is an address that directs information between two network destinations (or hosts), whereas a port determines which application will receive the data.
How many servers can you have on your computer?
An infinite number. Each application runs on it's own server (and port).
Why does the code below throw an undefined error? var content; fs.readFile('./Index.html', function read(err, data) { if (err) { throw err; } content = data; }); console.log(content);
Because the fs.readFile method is using asynchronous execution. this means the callback function read() will not be executed until the entire file is read, so the variable content has not been initialized. In other words... The asynchronous execution method stipulates that while the file content is being loaded, execution should continue to the next command - console.log(content).
What is the difference between a library and a dependency?
Both are libraries that are available to be used in node.js. When my program needs it to run, however, it becomes a dependency.
What is abstraction (in programming)?
Creating generalized functionality to handle different 'kinds' of objects that are of the same 'type'. Without abstraction, we would have to re-write the same code over and over again. We don't do this because we can represent code as a 'name' that encapsulates the entire operation.
What is Express.js ?
Express is a Node.js framework that abstracts many common operations when building JavaScript applications. The methods for handling HTTP requests, for example, are handled in simplified .get, .post, .put, .delete methods.
what does HTTP stand for, and what is it?
Hyper Text Transfer Protocol. These are the "rules" for how two browsers (clients) "communicate" (send information back and forth) with each other and with web servers. https://en.wikipedia.org/wiki/Communication_protocol
What is middleware?
In request handling, middleware is functionality that allows you to perform actions irrespective of the request but that will be required by all requests. When an http request is sent, for example, it is for the html file. The CSS and JavaScript files will also be needed for the full user experience. The middleware function app.use() allows the CSS and JavaScript files to be sent to the client along with the html page requested. *** The user requests the page, and the page requests the middleware dependencies.
what does the .listen method do?
It "turns on" your server. Until this method is called, your server is not "listening" for requests on it's port. When this is called, requests can come in and be served.
What does the '/' symbol mean?
It means the 'root', the current directory
What are regular expressions?
Patterns used to match character combinations. -------------Node.js regex-------------- /a/ - only a '/contact ' = only contact /contact/ = more versatile /[a-z]/ = any character "a" to "z
why do we use the .static method?
We use this method when a resource location will exist for the lifetime of the application. We pass this through the app.use method to declare that middleware resources needed will always be in this folder. The .static method is also middleware itself app.use(express.static('images'))
What is a deadlock?
When one process is waiting on a resource that is held by another process, which is also waiting on a resource held by another process, which is also waiting on a resource held by another process, etc, the system is said to be in deadlock.
What does the "require" keyword mean
it loads built in Node.js modules that your code depends on to run.
What does rendering mean?
loading or producing gathered (or first gathering, then loading) data
