Back to the ROUTES: Express Routing - 401-advanced-javascript-aimurphy/seattle-javascript-401n13 GitHub Wiki

Express Routing

Starting with App

When we write our servers we start with something like this:

'use strict'
const express = require('express');
const app = express(); 

app.get('/_endpoint_', _call-back-function_(req, resp){
resp.send('herro world');
}

app is actually an object, an express object. It also contains methods that correspond to HTTP methods. app, the object, listens for requests that match the route and methods it is assigned. When a match comes by, it runs a callback (or two, or more--it can run multiple). *Make sure to include next(); after the callback or else that function will continue to run and control will not be passed on--you're blocking the stack.

app can also use middleware as a function, and in this case would require the method .use to do so.

app HTTP methods:

Express supports the following routing methods corresponding to the HTTP methods of the same names:

checkout copy delete get head lock
merge mkactivity mkcol move m-search notify
options patch post purge put report
search subscribe trace unlock unsubscribe (all)

Sources:

ExpressJS: Routing

scotch.io: learn to use the new router