Example using the controller with express.Router()

PHOTO EMBED

Mon Apr 08 2024 15:31:50 GMT+0000 (Coordinated Universal Time)

Saved by @jamzlego #nodejs

const express = require('express');
const aboutController = require('../controller/about');

const router = express.Router();

router.get('/about', aboutController.getAbout);


module.exports = router;
content_copyCOPY

Directory Name: routes Filename: about.js In this snippet we have extracted our routes to their own page where we incorporate the controller. By separating each page into its own routes we create a lean server file. It makes it easier to scale and for other developers to understand the project structure quickly.