0.0.2 • Published 7 months ago

roufs v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Roufs: Simplified Routing for Node.js

Roufs (pronounced "roofs") is a straightforward and practical routing solution for Node.js API frameworks, inspired by the routing approach used in Next.js. This module is designed to work seamlessly with Express.js, but it can be easily adapted for use with other popular frameworks as well.

Features

  • Automatic route mapping
  • Supports parameterized routes
  • Minimal configuration required

Getting Started

To get started with Roufs in an express project, follow these steps:

  1. Install Roufs:

    npm install roufs
  2. Create your route handler modules in the desired directory structure. For example:

        -   ./routes
        ├── index.js
        ├── authors
        │   ├── GET.js
        │   └── POST.js
        └── books
            ├── index.js
            └── [bookid].js
  3. Integrate Roufs into your Express.js server in your index.js file:

        const express = require("express");
        const roufs = require("roufs");
        const app = express();
    
        // Specify the path to your route handler modules
        app.use(roufs('./routes'));
    
        app.listen(5001, () => {
            console.log("Server is up and running on port 5001!");
        });

Defining Routes

Define your route handlers in separate modules within the ./routes directory (relative to root of project). You can use simple functions or objects with HTTP method-specific functions to define your handlers. For example:

// Example 1: ./routes/authors/GET.js
module.exports = (req, res) => res.send("Response");

// Example 2: ./routes/books/index.js
module.exports = {
    GET: (_, res) => res.send("GET:/books"),
    POST: (_, res) => res.send("POST:/books")
}

// Example 3: ./routes/books/[bookid].js
module.exports = {
    GET: (req, res) => res.send(req.params), // params = { bookid: "path-param" }
};

Dynamic Routes

Roufs supports dynamic routes. You can create parameterized routes like /books/[bookid], and the module will handle them automatically.

How Roufs Works

Roufs uses a clever mechanism to traverse your route directory structure and dynamically match incoming requests to their corresponding handlers. It simplifies route management by abstracting away the complexities.

Contributing

If you'd like to contribute to Roufs or have any questions, feel free to reach out. Your contributions and feedback are welcome.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Please make sure to replace `"my-project"` with the actual name of your project and adjust the content as needed. Additionally, consider adding a license file (`LICENSE`) to your project directory and specifying the appropriate license for your module.
0.0.2

7 months ago

0.0.1

7 months ago