Code Fellows Notes
Objects
No, an important difference between function declarations and class declarations is that while functions can be called in code that appears before they are defined, classes must be defined before they can be constructed.
A constructor, somewhat like its namesake, allows us to create and initialize an object created with a class. “this” is representative of its context in reference to the object that is currently executed the code or function, for example if typed in the browser console it will be in relation to the current window.
how an applications endpoints (URIs) respond to client requests. You define routing using methods of the Express app object that correspond to HTTP methods; for example, app.get() to handle GET requests and app.post to handle POST requests.
Routing methods specify a callback function (sometimes called “handler functions”) called when the application receives a request to the specified route (endpoint) and HTTP method. A route method is derived from one of the HTTP methods, and is attached to an instance of the express class.
Route paths, in combination with a request method, define the endpoints at which requests can be made. Route paths can be strings, string patterns, or regular expressions.
next
as a parameter to a route handler and what must you do if next
has been passed to your middleware as a parameter?You can provide multiple callback functions that behave like middleware to handle a request. The only exception is that these callbacks might invoke next(‘route’) to bypass the remaining route callbacks. You can use this mechanism to impose pre-conditions on a route, then pass control to subsequent routes if there’s no reason to proceed with the current route.
It is a mini express application without all the bells and whistles of an express application, just the routing stuff.
express.Router()
in an express server?by calling an instance of express.Router();
e.g. var router = express.Router();
Route middleware in Express is a way to do something before a request is processed. This could be things like checking if a user is authenticated, logging data for analytics, or anything else we’d like to do before we actually spit out information to our user.