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
Are file operations using the fs module synchronous or asynchronous?
asynchronous writefile and readfile
synchronous writefilesync and readfilesync
What is a client?
software making use of party requesting service
program/computer that requests access from another program/computer
What is a server?
provider of the service or resource
program/computer that provides functionality to another program/computer
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
The browser looks up the IP address for the domain name via DNS. The browser sends a HTTP request to the server.
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
The browser looks up the IP address for the domain name via DNS. The browser sends a HTTP request to the server.
What is on the first line of an HTTP response message?
protocol version, status code, status text
What are HTTP headers?
let the client and the server pass additional information with an HTTP request or response
meta data for the response or request
Is a body required for a valid HTTP message?
no, they are optional
What is NPM?
large Software Registry for users to share and borrow packages
the registry is a large public database of JavaScript software and the meta-information surrounding it.
the website
the Command Line Interface (CLI)
the registry
node package manager
What is a package?
A package is a file or directory that is described by a package.json file
one or more files with a package.json
packages have a package.json
What happens when you add a dependency to a package with npm?
npm will download dependencies and devDependencies that are listed in package. json that meet the semantic version requirements listed for each.
package was downloaded by the registry in the directory updates the package dependencies in the package.json
How do you add express to your package dependencies?
create a package.json then install it from the npm registry
npm install express
What Express application method starts the server and binds it to a network PORT?
listen method
app.listen()
How do you mount a middleware with an Express application?
use method of app object
Middleware functions are functions that have access to the request object (req), the response object (res)
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
the request object ( req ), the response object ( res )
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
Content-Type: application/json; charset=utf-8
What does the express.json() middleware do and when would you need it?
to parse the incoming requests with JSON payloads and is based upon the bodyparser
What is Webpack?
popular module bundling system built on top of Node. js JavaScript module bundler that supports both commonJS and ECMA6 makes
How do you add a devDependency to a package?
–save-dev flag
What is an NPM script?
a way to bundle common shell commands for your project
property of your package.json file
commands for the npm
command line command
How do you execute Webpack with npm run?
installing webpack and the webpack-cli npm run (name of script)
How are ES Modules different from CommonJS modules?
CommonJS loads modules synchronously, ES modules are asynchronous
commonJS const TodoList = require(‘./todo-list’);
ES import TodoList from ‘./todo-list’;
dont use require vs import keyword
export keyword vs module.exports
imported with { }
es modules are a part of the JS language and commonJS is not
What kind of modules can Webpack support?
ECMAScript modules CommonJS modules AMD modules Assets WebAssembly modules
What is React?
A JavaScript library for building user interfaces for building user interfaces based on UI components.
What is a React element?
an element in the dom
React elements are plain objects,
A React element is an object representation of a DOM node or component instance building blocks
an object describing a component instance or DOM node and its desired properties
How do you mount a React element to the DOM?
with the render method of the reactdom object
ReactDOM.render(element, container[, callback])
What does express.static() return?
the static files requested
returns a middleware function
What is the local __dirname variable in a Node.js module?
The directory name of the current module
tells you the absolute path of the directory containing the currently executing file
absolute path of the directory that the module is in
What does the join() method of Node’s path module do?
combines all the string path arguments together and returns a file path