express-flow-extensions

1.0.5 • Public • Published

express-flow-extensions

Set of tools to accelerate the development with express using a functional approach.

For more information see manual/Usage and manual/Documentation

Getting Started

To install:

npm i --save express-flow-extensions

In your project:

const expressExtensions = require('express-flow-extensions')
const { Joi, enableReturn, flow } = expressExtensions
const express = require('express')
const bodyParser = require('body-parser')
const R = require('ramda')
const authentication = require('./middleware/authentication')
const db = require('./db')
 
const app = expressExtensions(express())
 
app
.use(bodyParser.json())
.addRouters([
  {
    method: 'GET',
    path: '/posts',
    handler: enableReturn(() => db.findAllPosts())
  },
  {
    method: 'GET',
    path: '/tags/:postId',
    validation: {
      params: {
        postId: Joi.number().integer()
      }
    },
    middleware: [authentication],
    handler: flow(
      R.path(['params', 'postId']),
      db.findPostById,
      db.findTagsByPost
    )
  },
  {
    method: 'GET',
    path: '/tags',
    handler: (req, res) => {
        db.findAllTags()
        .then((tags) => res.send(tags))
    }
  }
])
 
await app.listenAsync(3000)

Package Sidebar

Install

npm i express-flow-extensions

Weekly Downloads

7

Version

1.0.5

License

MIT

Unpacked Size

1.81 MB

Total Files

78

Last publish

Collaborators

  • madoos