# express-handle

> Lightweight library that allows you to dynamically load and manage your express.js routes!

Latest version **0.0.3** (published 2023-03-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-handle
pnpm add express-handle
yarn add express-handle
bun add express-handle
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2023-03-23 |
| First published | 2023-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | abdlmutii |
| Maintainers | abdlmutii |
| Keywords | express, routes, router, middleware, tree, directory, recursive |

## Links

- npm: https://www.npmjs.com/package/express-handle
- npm.io page: https://npm.io/package/express-handle

## Dependencies (2)

- [express](https://npm.io/package/express.md) ^4.18.2
- [cli-table](https://npm.io/package/cli-table.md) ^0.3.11

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2023-03-23
- 0.0.2 — 2023-03-23
- 0.0.1 — 2023-03-23

## README

# Express handle
<a href="https://discord.gg/8UqPNbeYBv"><img src="https://img.shields.io/discord/1077492444574261339?style=for-the-badge&color=5865F2&logo=discord&logoColor=white&label=Abdlmu'tii" alt="Discord server" /></a><br>
This is a Node.js package that automatically loads routes in an Express app from files in a specified folder. It also allows for customization of middleware and parameters for the loaded routes.

## Installation
```sh
npm install express-handle
```


## Usage
```js
const express = require('express');
const { handler } = require('express-handle');

const app = express();

const options = {
folder: './routes',
middlewares: [ /* array of middleware functions */ ],
params: { "param1": "value1", "param2": "value2" },
notfound: (req, res) => { /* custom 404 handler function */ },
tree: true // display route table
};

handler(app, options);

app.listen(3000, () => console.log('App is listening on port 3000'));
```


## Route File Example

Here is an example of a route file that can be loaded:
```js
module.exports = {
name: '/hello',
method: 'GET',
description: 'Returns a hello message',
disabled: false,
run: (req, res) => {
   res.send('Hello World!');
  }
}
```


## Explanation:

Suppose we have a route file `routes/hello.js` as shown above. When we run the Express app with the auto loader and navigate to `http://localhost:3000/hello`, we will see the message "Hello World!" displayed in the browser.

Additionally, if the `tree` option is set to true, a table showing all loaded routes will be displayed in the console when the app is started.

```
Commands
┌────────┬──────────────────────┬────────┬─────────┐
│ Name │ Description │ Method │ Disabled│
├────────┼──────────────────────┼────────┼─────────┤
│ /hello │ Returns a hello message │ GET │ false │
└────────┴──────────────────────┴────────┴─────────┘
```

**Note:** To use the `params` option to pass parameters to the route file's `run` function, make sure to pass a stringified JSON object as the value of the option.

## Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

## Credits
Credits goes to [abdlmutii](https://github.com/abdlmutii), if you like this npm package please remember to check other work i've done on github and `octo star abdlmutii/octoshell` 😉.<br>
**Email**: [abdlmutii@outlook.com](mailto:abdlmutii@outlook.com)
<br>
**Business Email**: [abdlmutii.buz@outlook.com](mailto:abdlmutii.buz@outlook.com)

---
_Source: https://npm.io/package/express-handle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
