Defining routes for the app

From the examples in Chapter 1, What is Express? and Chapter 2, Your First Express App, we know how routes and route handler callback functions look like. Here is an example to refresh your memory:

app.get('/', function(req, res) {
  res.send('welcome');
});

Routes in Express are created using methods named after HTTP verbs. For instance, in the previous example, we created a route to handle GET requests to the root of the website. You have a corresponding method on the app object for all the HTTP verbs listed earlier.

Let's create a sample application to see if all the HTTP verbs are actually available as methods in the app object:

var http = require('http'); var express = require('express'); var app = express(); // Include ...

Get Express Web Application Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.