Skip to content

doiska/express-router-fs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express File-based Router (NextJS style)

Simplify your Express routing. Organize routes using file and directory structures, and let this tool auto-register them.

Installation

npm install express-router-fs --save

Quick Start

Just like in NextJS, your routes are declared based on their directory and file structure. Ensure each directory has an index file. In your main app file (where your Express app is initialized):

const app = express();

setupFileRouter(app, {
    directory: 'routes',
    extensions: ['.ts', '.js']
});

Directory example:

Simple example:

routes/
|-- index.ts
|-- posts/
|-- |-- index.ts

You can also use Slugs (> v1.2.0)!

routes/
|-- index.ts
|-- posts/
|-- |-- [postId]
|-- |-- |-- index.ts

The handler methods are declarated using exported functions, for example:

export function GET(request: Request, response: Response) {
    console.log('Received GET request!')
}

export function POST(request: Request, response: Response) {
    console.log('Received POST request!')
}

About

Express File System Router - NextJS like

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published