Reader small image

You're reading from  JavaScript from Frontend to Backend

Product typeBook
Published inJul 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781801070317
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Eric Sarrion
Eric Sarrion
author image
Eric Sarrion

Eric Sarrion is a trainer and a developer as an independent consultant. He has been involved in all kinds of IT projects for over 30 years. He is also a long time author in web development technologies and is renowned for the clarity of his explanations and examples.
Read more about Eric Sarrion

Right arrow

Using routes with Express

Routes indicate the processing to be performed based on the requested URL. Compared to what we wrote when using the http module of Node.js with the createServer(callback) method, this consists of writing the content of the callback(req, res) function according to the req request received.

The routes are described in the app.js file, which is the main file created by Express. Let’s examine its content.

The initial content of the app.js file

To understand how routes work in Express, open the app.js file located in the main application directory, and you will see the content of this file, like this:

app.js file

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users&apos...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
JavaScript from Frontend to Backend
Published in: Jul 2022Publisher: PacktISBN-13: 9781801070317

Author (1)

author image
Eric Sarrion

Eric Sarrion is a trainer and a developer as an independent consultant. He has been involved in all kinds of IT projects for over 30 years. He is also a long time author in web development technologies and is renowned for the clarity of his explanations and examples.
Read more about Eric Sarrion