5.4.0 • Published 1 year ago

@a-project-net/easy-express v5.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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

npm i @a-project-net/easy-express
yarn add @a-project-net/easy-express

Quick Start

app.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

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

const { EasyExpressApplication } = require('@a-project-net/easy-express');

const app = new EasyExpressApplication;

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

app.start(3000);

Listener

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

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

Utils

logging additions

//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

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

5.4.0

1 year ago

5.3.0

1 year ago

5.2.1

1 year ago

5.2.0

1 year ago

5.0.0

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

0.0.1

1 year ago

2.2.0

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago