Express Sweet API Reference - v3.0.0
    Preparing search index...

    Class Router

    Set up URL routing based on file structure in the routes directory. Automatically maps route files to URL endpoints using file-based routing. Supports nested routing and default routes.

    // Basic routing: routes/user.js responds to GET /user
    import {Router} from 'express';

    const router = Router();
    router.get('/', (req, res) => {
    res.send('Hello World');
    });

    export default router;
    // Nested routing: routes/api/users.js responds to GET /api/users
    import {Router} from 'express';

    const router = Router();
    router.get('/', (req, res) => {
    res.send('Hello World');
    });

    export default router;
    // Default routing configuration in config/config.js
    export default {
    default_router: '/blog' // routes/blog.js handles root URL "/"
    };
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Mount file-based routing on Express application. Scans the routes directory and automatically maps files to URL endpoints.

      Parameters

      • app: Express

        Express application instance

      Returns Promise<void>

      // This method is called automatically by express-sweet.mount()
      import Router from './routing/Router';

      await Router.mount(app);