# node-bits-express

> Adds express functionality to NodeBits

Latest version **0.0.23** (published 2019-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-bits-express
pnpm add node-bits-express
yarn add node-bits-express
bun add node-bits-express
```

## 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.23 |
| Published | 2019-06-14 |
| First published | 2016-12-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 189.5 KB |
| Known vulnerabilities | 0 (+11 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Josh Gretz |
| Maintainers | jgretz |

## Links

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

## Dependencies (8)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [multer](https://npm.io/package/multer.md) ^1.4.1
- [express](https://npm.io/package/express.md) ^4.17.1
- [node-bits](https://npm.io/package/node-bits.md) ^0.0.35
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [compression](https://npm.io/package/compression.md) ^1.7.4
- [express-fileupload](https://npm.io/package/express-fileupload.md) ^1.1.5

## Recent versions

- 0.0.23 (latest) — 2019-06-14
- 0.0.21 — 2017-07-14
- 0.0.20 — 2017-06-21
- 0.0.19 — 2017-06-19
- 0.0.18 — 2017-06-16
- 0.0.17 — 2017-06-16
- 0.0.16 — 2017-06-15
- 0.0.15 — 2017-04-16
- 0.0.14 — 2017-03-25
- 0.0.13 — 2017-03-06
- 0.0.12 — 2017-03-02
- 0.0.11 — 2017-02-24
- 0.0.10 — 2017-02-09
- 0.0.9 — 2017-02-09
- 0.0.8 — 2017-02-08
- … 7 more at https://npm.io/package/node-bits-express/versions

## README

# node-bits-express
node-bits-express wraps the popular web framework [express](http://expressjs.com/). It iterates through the routes provided by other node-bits packages and exposes them as routes in express. It also exposes a couple of helpers to make setting up your server extremely simple.

## Install
```
npm install node-bits-express --save
```

or

```
yarn add node-bits-express
```

## Configuration
node-bits-express accepts an object to detail its configuration. Each property is detailed below.

```
import nodeBits, { GET,POST,PUT,DELETE,OPTIONS } from 'node-bits';
import nodeBitsExpress, { cors, bodyParser } from 'node-bits-express';

nodeBits([
  nodeBitsExpress({
    port: 3000,
    configurations: [cors({ methods: [GET,POST,PUT,DELETE,OPTIONS] }), bodyParser({limit: '5mb'})],
    hooks: []
  })
];
```

### Port
This is the port the server should listen on. Often this is expressed as the following example to allow runtime configuration:

```
port: process.env.port || 3000,
```

### Configurations
Configurations are simple functions that setup an attribute of the express server at boot. They are specified as to node-bits-express as items in an array.

```
configurations: [cors({ methods: [GET,POST,PUT,DELETE,OPTIONS] }), bodyParser],
```

The signature for these functions is: ``` (app, config) => {} ```. The first parameter is the express application. The second parameter is the overall config of node-bits.

node-bits-express exposes multiple configurations that we have found used across different projects.

#### cors
cors uses the [cors](https://www.npmjs.com/package/cors) npm package. It accepts an object that matches the cors config you can find in their documentation. Most often it is simply passing in the methods to which you want cors to apply (as seen in the example above).

#### bodyParser
[body-parser](https://www.npmjs.com/package/body-parser) is a middleware for express that will parse the body of a http call and place it at req.body.

It accepts an object that matches the config you can find in their documentation.

* note: body-parser does NOT handle multipart data. See their documentation for suggestions.

#### noCache
Depending on what's consuming your api, there are times when get api calls are cached (I'm looking at you IE 11). NoCache adds a middleware to the express response chain to add the following headers:

```
'Cache-Control': 'no-cache, no-store, must-revalidate'
'Pragma': 'no-cache'
'Expires': 0
```

### Hooks
Hooks allow you to hook into a certain points in the server lifecycle. Right now the two options are BEFORE_CONFIGURE_ROUTES and AFTER_CONFIGURE_ROUTES.

The main use of the hook is the node-bits-jwt bit.

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