# @a-project-net/easy-express

> Lightweight wrapper over express, allowing to create applications comfortably

Latest version **5.4.0** (published 2023-01-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @a-project-net/easy-express
pnpm add @a-project-net/easy-express
yarn add @a-project-net/easy-express
bun add @a-project-net/easy-express
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.4.0 |
| Published | 2023-01-05 |
| First published | 2023-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | APNET |
| Maintainers | a-project-net |
| Keywords | express, api, apnet, a-project-net |

## Links

- npm: https://www.npmjs.com/package/@a-project-net/easy-express
- npm.io page: https://npm.io/package/@a-project-net/easy-express

## Dependencies (4)

- [express](https://npm.io/package/express.md) ^4.18.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.20.1
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.6
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.15

## Recent versions

- 5.4.0 (latest) — 2023-01-05
- 5.3.0 — 2023-01-05
- 5.2.1 — 2023-01-05
- 5.2.0 — 2023-01-05
- 5.0.0 — 2023-01-03

## README

# APNET Easy-Express
## _Lightweight wrapper over express, allowing to create applications comfortably_

Warning! The project is actively under development. Some features may not work!

## Features

- Quick creation of an application with basic features
- BodyParser out of the box
- CookieParser out of the box
- Handy log system
- Easy creation of large APIs

## Installation
```sh
npm i @a-project-net/easy-express
```

```sh
yarn add @a-project-net/easy-express
```

## Quick Start
__app.js__
```js
const { EasyExpressApplication } = require('@a-project-net/easy-express');
//creating new app instance
const app = new EasyExpressApplication;

//starting server on port
app.start(3000);
```

## Routing

__router.js__
```js
const { Listener } = require('@a-project-net/easy-express');

module.exports = [
    // endpoint
    new Listener({
        path: 'welcome',
        //method: get, post or parent(default)
        type: 'get',
        //endpoint listeners
        listener: ({ res }) => {
            res.send('hey!');
        },
    }),
    new Listener({
        path: 'user',
        //default method: parent

        //child endpoints
        listeners: [
            new Listener({
                path: '/',
                type: 'get',
                listener: ({ res }) => {
                    return res.send('...');
                }
            }),
            new Listener({
                path: 'setUsername',
                type: 'post',
                listener: ({ body, log, res }) => {
                    log(body);
                    return res.send('done');
                }
            }),
        ]
    })
];
```
__app.js__
```js
const { EasyExpressApplication } = require('@a-project-net/easy-express');

const app = new EasyExpressApplication;

//setup router
app.setupAPIListener('api', require('./router'));

app.start(3000);
```

## Listener
```js
new Listener({
    //path of endpoint
    path: 'welcome',
    //method (post, get)
    type: 'get',
    //handler
    listener: ({ 
        //express response
        res, 
        //express request
        req, 
        //logger function
        log, 
        //body, from body-parser
        body,
        //cookies, from request
        cookies,
        //for middlewares
        next,
    }) => {
        //your code
        return res.send('welcome');
    }
})
```

## Logger
```js

//displays request method, endpoint path and your message. must be provided to endpoint handler!
log('my message')
```

## Utils
__logging additions__
```js
//some colors for logs :)
const { logger: { colors } } = require('@a-project-net/easy-express');
//e.g. red text
log(colors.FgRed + 'red message!');
```

__how to get express app instance__
```js
const { EasyExpressApplication } = require('@a-project-net/easy-express');
//creating new app instance
const app = new EasyExpressApplication;

//getting instance
app.getInstance().use(something...)

//starting server on port
app.start(3000);
```

## License

MIT

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