# bunserver

> tiny web framework

Latest version **0.6.7** (published 2021-03-01) · GPL-2.0-only license · 0 weekly downloads

## Install

```sh
npm install bunserver
pnpm add bunserver
yarn add bunserver
bun add bunserver
```

## 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.6.7 |
| Published | 2021-03-01 |
| First published | 2021-02-26 |
| Weekly downloads | 0 |
| License | GPL-2.0-only |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Lars Feldeisen |
| Maintainers | larsonnn |
| Keywords | webserver, server, framework |

## Links

- npm: https://www.npmjs.com/package/bunserver
- Repository: https://github.com/larsonnn/bun
- Homepage: https://github.com/larsonnn/bun#readme
- Issues: https://github.com/larsonnn/bun/issues
- npm.io page: https://npm.io/package/bunserver

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 0.6.7 (latest) — 2021-03-01
- 0.6.6 — 2021-03-01
- 0.6.4 — 2021-03-01
- 0.6.3 — 2021-02-27
- 0.5.4 — 2021-02-27
- 0.5.2 — 2021-02-27
- 0.5.1 — 2021-02-27
- 0.5.0 — 2021-02-27
- 0.4.1 — 2021-02-26
- 0.4.0 — 2021-02-26
- 0.0.8 — 2021-02-26
- 0.0.7 — 2021-02-26
- 0.0.6 — 2021-02-26
- 0.0.5 — 2021-02-26

## README

![main](https://github.com/larsonnn/bun/actions/workflows/main.yml/badge.svg?branch=main)

# Bun - tiny nodejs web framework

### WIP

## Features

- middleware
- - easy setup after or before routing
- dynamic routing

## install

```sh
npm i bunserver
```

## properties

```
https://nodejs.org/docs/latest-v14.x/api/http.html#http_class_http_clientreques
req (request object)
  .body // post body
  .rawQueries // queries not an object yet
  .params // dynamic routing object
  
https://nodejs.org/docs/latest-v14.x/api/http.html#http_class_http_incomingmessage
res (response object)
  .setHeader() // set any headers
  .status() // set statuscode
  .send() // string body
  
you can use it like this
  console.log(req.body);
  console.log(req.params.id) // /users/:id/
  res.setHeader("Content-Type", "application/json")
  res.status(200).send(JSON.stringify({ message: "message"}));

```
## usage

```js
const bun = require("bunserver");
bun.prefix = "/api/";
bun.routes = [
  {
    path: "/users/",
    fun: async (req, res) => console.log("Im a route"),
    method: "GET,POST",
  },
];
bun.before((req, res) => {
  req.newstuff = "this does not normally exist";
});
bun.before([(req, res) => (req.newstuff = "change it")]);
bun.after((req, res) => {
  if (res.writeStatus === 200) {
    res.status(400); //trolling
  }
});

bun.start(1234, "0.0.0.0");
```

## benchmark autocannon
```
Running 10s test @ http://localhost:8000
10 connections

┌─────────┬──────┬──────┬───────┬──────┬─────────┬─────────┬──────┐
│ Stat    │ 2.5% │ 50%  │ 97.5% │ 99%  │ Avg     │ Stdev   │ Max  │
├─────────┼──────┼──────┼───────┼──────┼─────────┼─────────┼──────┤
│ Latency │ 0 ms │ 0 ms │ 0 ms  │ 0 ms │ 0.01 ms │ 0.11 ms │ 9 ms │
└─────────┴──────┴──────┴───────┴──────┴─────────┴─────────┴──────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬──────────┬────────┬─────────┐
│ Stat      │ 1%      │ 2.5%    │ 50%     │ 97.5%   │ Avg      │ Stdev  │ Min     │
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼────────┼─────────┤
│ Req/Sec   │ 17295   │ 17295   │ 24863   │ 25279   │ 24089.46 │ 2174.5 │ 17287   │
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼────────┼─────────┤
│ Bytes/Sec │ 3.03 MB │ 3.03 MB │ 4.35 MB │ 4.42 MB │ 4.22 MB  │ 380 kB │ 3.03 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴──────────┴────────┴─────────┘

Req/Bytes counts sampled once per second.

0 2xx responses, 264953 non 2xx responses
265k requests in 11.02s, 46.4 MB read
```

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