# @byverdu/http-server

> Exported Express app to speed up other modules/prototypes that require a server

Latest version **1.1.6** (published 2023-05-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install @byverdu/http-server
pnpm add @byverdu/http-server
yarn add @byverdu/http-server
bun add @byverdu/http-server
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2023-05-19 |
| First published | 2022-09-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | @byverdu |
| Maintainers | byverdu |
| Keywords | express, boilerplate, http-server, static server |

## Links

- npm: https://www.npmjs.com/package/@byverdu/http-server
- Homepage: https://github.com/byverdu/http-server#readme
- Issues: https://github.com/byverdu/http-server/issues
- npm.io page: https://npm.io/package/@byverdu/http-server

## Dependencies (4)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [morgan](https://npm.io/package/morgan.md) ^1.10.0
- [express](https://npm.io/package/express.md) ^4.18.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.20.0

## Recent versions

- 1.1.6 (latest) — 2023-05-19
- 1.1.5 — 2023-05-19
- 1.1.4 — 2023-05-16
- 1.1.1 — 2023-05-16
- 1.0.70 — 2023-05-15
- 1.1.0 — 2023-05-15
- 1.0.69 — 2022-10-10
- 1.0.60 — 2022-10-10
- 1.0.58 — 2022-10-10
- 1.0.43 — 2022-10-10
- 1.0.47 — 2022-10-10
- 1.0.42 — 2022-10-10
- 1.0.46 — 2022-10-10
- 1.0.45 — 2022-10-10
- 1.0.44 — 2022-10-10
- … 25 more at https://npm.io/package/@byverdu/http-server/versions

## README

![npm](https://img.shields.io/npm/v/@byverdu/http-server?style=plastic) ![Codecov](https://img.shields.io/codecov/c/github/byverdu/http-server?style=plastic) ![Github](https://img.shields.io/github/checks-status/byverdu/http-server/master?style=plastic) ![lastCommit](https://img.shields.io/github/last-commit/byverdu/http-server?style=plastic)

# http-server

This package is meant to be used as a quick way to setup an Express application. The module does not have too much defined. The default functionality is the following.

- `cors` enabled
- logs using `morgan`
- static assets served from `express.static('public')`
- `/health` endpoint to verify that the app is running.

## Params

Pass an object with the following properties:

```ts
interface Route {
  method: 'get' | 'delete' | 'post' | 'put' | 'patch'
  path: string // must start with "/"
  handler: function(Request, Response)
}

interface Params {
  port?: number  // defaults to 3000
  middleware?: Array<Express middleware> // defaults to []
  routes: Array<Route>
}
```

## How to use it

```sh
# install the module

> yarn add -D @byverdu/http-server
```

```js
// index.js
import { httpServer } from "@byverdu/http-server";
import path from 'path';

const routes = [
  {
    method: 'get',
    path: '/some-path',
    handler: (req, res) => {

      res.sendFile(path.resolve('./index.html'))
    }
  }
]

httpServer({routes})
```

In order to serve static files create a `public` folder and place them inside there.

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