Express Flashcards
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json charset optional
What does the express.json() middleware do and when would you need it?
parses incoming request bodies if payload is JSON
It parses incoming JSON requests and puts the parsed data in req.body.
It is needed when content type header is application/json in the HTTP request
What is the significance of an HTTP request’s method?
Indicate the method to be performed
To tell what function you want ran in the code, e.g. (delete, get etc.)
the intent of the client but does not do anything
Why should a full stack Web developer know that computer processes exist?
Full stack Web development is based on making multiple processes work together to form one application, so having at least a cursory awareness of computer processes is necessary. This will be extremely important when learning about applications made of multiple components, such as clients, servers, and databases.
web dev is based on making multiple processes work together to form one application
What is the process object in a Node.js program?
a global object that can be accessed inside any module without requiring it
How do you access the process object in a Node.js program?
since its global it can be accessed inside any module without requiring it
What is the data type of process.argv in Node.js?
array of strings
What is a JavaScript module?
a single .js file
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, __dirname LOCAL
Give two examples of truly global variables in a Node.js program.
process, console and global
What is the purpose of module.exports in a Node.js module?
Module exports are the instruction that tells Node. js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code
How do you import functionality into a Node.js module from another Node.js module?
use the require function keyword at the top of the file then relative url
What is the JavaScript Event Loop?
the event loop is responsible for executing the code, collecting and processing events, and executing queued sub-tasks
one task at a time to an extent
look at the task queue and pushes it to the stack
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking assignment takes affect immediately it is processed. A nonblocking assignment takes place at the end of processing the current “time delta”
blocking on the stack, nothing else can happen until it gets popped off
non blocking refers to the task not having asynchronous, off the stack
What is a directory?
a file system that contains references to other files
type of file that lists other files
What is a relative file path?
a short hand version of the file url with no root
file path from the current location
What is an absolute file path?
The url with all the information including the root of the file full URL that goes in href
starts with /
What module does Node.js include for manipulating the file system?
‘fs” module or file module
What method is available in the Node.js fs module for writing data to a file?
writeFile method