# ponaserv

> A mini but opinionated framework for your express apps.

Latest version **1.1.0** (published 2023-04-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install ponaserv
pnpm add ponaserv
yarn add ponaserv
bun add ponaserv
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-04-16 |
| First published | 2020-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Joaquim Neto |
| Maintainers | joaquimnet |
| Keywords | express, framework, services |

## Links

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

## Dependencies (4)

- [express](https://npm.io/package/express.md) ^4.18.2
- [app-root-path](https://npm.io/package/app-root-path.md) ^3.1.0
- [fastest-validator](https://npm.io/package/fastest-validator.md) ^1.16.0
- [recursive-readdir](https://npm.io/package/recursive-readdir.md) ^2.2.3

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-04-16
- 1.0.0 — 2023-04-15
- 0.2.0 — 2020-12-09
- 0.1.0 — 2020-11-28
- 0.0.1 — 2020-09-27

## README

<p align="center">
  <a href="https://ponaserv.vercel.app" target="_blank" rel="noopener noreferrer">
    <img width="180" src="https://ponaserv.vercel.app/logo.svg" alt="Ponaserv logo">
  </a>
</p>
<br/>
<p align="center">
  <a href="https://npmjs.com/package/ponaserv"><img src="https://img.shields.io/npm/v/ponaserv.svg" alt="npm package"></a>
  <a href="https://github.com/joaquimnet/ponaserv/actions/workflows/main.yml"><img src="https://github.com/joaquimnet/ponaserv/actions/workflows/main.yml/badge.svg?branch=main" alt="build status"></a>
  <a href="https://github.com/joaquimnet/ponaserv/blob/main/LICENSE.md"><img src="https://img.shields.io/npm/l/ponaserv" alt="license"></a>
</p>
<br/>

# Ponaserv

Easily map routes to request handlers.

## How to use

```javascript
/* server.js */
const { ponaserv } = require('ponaserv');
const express = require('express');
const path = require('path');

const app = express();

ponaserv(app, { services: path.join(__dirname, 'services') });

app.listen(3000, () => {
  console.log('App listening on port 3000');
});
```

## Service example

```javascript
/* services/hello.js */
const express = require('express');

module.exports = {
  name: 'hello-world',
  routes: {
    'GET /': 'sayHello',
    'GET /:message': 'specialHello',
    'POST /': 'jsonIsCool',
    'GET /math': 'math',
  },
  actions: {
    sayHello(req, res) {
      res.send('Hello World!');
    },
    specialHello(req, res) {
      const { message } = req.params;
      res.send(message.toUpperCase());
    },
    jsonIsCool: {
      middleware: [express.json()],
      handler(req, res) {
        const { body } = req;
        res.send({ yourData: body });
      }
    },
    math: {
      middleware: [express.json()],
      params: {
        a: 'number',
        b: 'number',
        $$strict: true,
      },
      handler(req, res) {
        const params = {...req.params, ...req.body, ...req.query};
        res.send(this.calc(params.a, params.b));
      }
    }
  },
  methods: {
    calc(a, b) {
      return a + b;
    }
  }
}
```

## Getting Started

Head to our [documentation](https://ponaserv.vercel.app) to learn more about ponaserv.

## License

Ponaserv is [MIT licensed](./LICENSE).

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