express-router-fs
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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!')
}

Readme

Keywords

none

Package Sidebar

Install

npm i express-router-fs

Weekly Downloads

2

Version

1.2.0

License

ISC

Unpacked Size

11.4 kB

Total Files

6

Last publish

Collaborators

  • doiska