app.getline in Express. While the Express code is slightly longer in this simple example, Express functionality like
app.getallows our server code to be much better decomposed and organised than Node HTTP does. We will elaborate on this in the following section.
createServer, Express sets the request listener only for a specific path
app.get. This simple but significant change allows Express to provide different request handler callbacks for each type of request it gets, greatly improving the decomposition of our server. It provides a framework for Express to support larger applications with more types of requests.
app.getare called "routing methods", and they help Express send each request to the relevant request handlers. We often refer to routing methods as "routes" for short. There are 2 ways in which routing methods filter requests: HTTP Methods and URL Paths.
app.get. To set a request handler for a POST method we would use
app.post. The same applies for PUT and DELETE.
wow-bananas. However, best practice is to name application paths more precisely, to help app users better anticipate what we will show them.
app.<METHOD>are 1 form of Express "middleware", where middleware are functions with access to Express request and response objects, that are executed in the order they are bound to the
appobject, until any middleware sends a response back to the client.
/two-dice-rollsthat rolls two dice and outputs their values to the client.
/two-dice-rollswith Chrome and with
curl. Verify we get the same responses.