# express-dual

> express-dual ============

Latest version **0.0.4** (published 2016-06-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install express-dual
pnpm add express-dual
yarn add express-dual
bun add express-dual
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2016-06-15 |
| First published | 2016-04-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jrop |

## Links

- npm: https://www.npmjs.com/package/express-dual
- Repository: https://github.com/jrop/express-dual
- Homepage: https://github.com/jrop/express-dual#readme
- Issues: https://github.com/jrop/express-dual/issues
- npm.io page: https://npm.io/package/express-dual

## Recent versions

- 0.0.4 (latest) — 2016-06-15
- 0.0.3 — 2016-04-20
- 0.0.2 — 2016-04-20
- 0.0.1 — 2016-04-20

## README

express-dual
============

> Split your express logic into separate data-fetching/view-rendering functions

# Installation

```sh
npm install --save express-dual
```

# Use

```js
...
const dual = require('express-dual')
const app = express()
app.get('/', dual()
	.data(function (req) {
		return { my: 'data' }
	})
	.view(function (req, res, data, next) {
		res.render('index', data)
	}))
```

When a request is made with the header `Accept` set to `application/json`, the middleware will respond with the data encoded as JSON, otherwise the middleware will call your view function.

# API

## dual([ dataCallback, [ viewCallback ] ]) : DualMiddleware

> Create dual middleware

## DualMiddleware.data(dataCallback) : DualMiddleware

> Attach a data-fetching function to middleware

The `dataCallback` function may return data immediately, or return a promise.  The signature of `dataCallback` is `function (request) => Object|Promise`

## DualMiddleware.view(viewCallback) : DualMiddleware

> Attach a view-rendering function to middleware

The signature of `viewCallback` is `function (request, response, data, next)`

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