A simple and small practical server built using Express. To begin, the variable app is initialized by calling the express() function from the express library. The require command instructs Node to import the library express and assign it to a local variable (also called express).
The three routes which i defined are :
Expecting the name of one of the books as input
A fallback from the previous route, in case the name provided was not found
A default route used to access the application’s home page.
The parameter next refers to a function. The next command instructs Express to try processing the next route matching the current request. In this example, entering the URL /books/ is intercepted by the first defined route (/books/:name?) rather than the second (/books). Since there was no name supplied, the logic will fall through to the default case in the switch statement at which point the next() function will be called. The next route (/books) contains the expected response.The question mark after the :name parameter indicates that the name is an optional input—this route will load even if no name is provided.