@barajs/express
TypeScript icon, indicating that this package has built-in type declarations

1.7.0 • Public • Published

Bara with Express integration

Bara makes it able to setup and run the Express server in a minute.

Install

npm install --save @barajs/bara @barajs/express --registry https://npm.pkg.github.com

Usage

import { run, app, act, cond } from '@barajs/bara'

import Express, {
  whenExpressStarted,
  whenAnyGet,
  whenAnyPost,
  hasGetQuery,
  WhenRequest,
  hasPostPath,
} from '@barajs/express'

run(
  app({
    portion: [Express({ port: 3200 })],
    trigger: [
      whenExpressStarted(
        act(({ port }: any) =>
          console.log(`Express server started on http://localhost:${port}`),
        ),
        act(() => console.log('Hello from Bara trigger')),
      ),
      whenAnyGet(
        cond(
          hasGetQuery('first'),
          act(({ request, response }: WhenRequest) => {
            const { query } = request
            response.send({ success: true, query })
          }),
        ),
      ),
      whenAnyPost(
        cond(
          hasPostPath('/webhook'),
          act(({ request, response }: WhenRequest) => {
            const { query, originalUrl } = request
            response.send({ success: true, query, originalUrl })
          }),
        ),
      ),
    ],
  }),
)

Readme

Keywords

none

Package Sidebar

Install

npm i @barajs/express

Weekly Downloads

3

Version

1.7.0

License

MIT

Unpacked Size

37.8 kB

Total Files

33

Last publish

Collaborators

  • nampdn