0.6.7 • Published 3 years ago

bunserver v0.6.7

Weekly downloads
213
License
GPL-2.0-only
Repository
github
Last release
3 years ago

main

Bun - tiny nodejs web framework

WIP

Features

  • middleware
    • easy setup after or before routing
  • dynamic routing

install

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

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
0.6.7

3 years ago

0.6.6

3 years ago

0.6.4

3 years ago

0.6.3

3 years ago

0.5.4

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago