npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bnnuy

v0.3.7-1

Published

A fast, lightweight, simple, and easy to use framework for Bun's HTTP API.

Downloads

36

Readme

bnnuy

Bnnuy is a future framework for Bun's HTTP API. It is currently in development and is not ready for use.

Philosophy

Bnnuy has to be:

  • Fast as possible.
  • Lightweight.
  • Simple, but powerful when you need it.
  • Dynamic.

Basic syntax

The syntax is pretty similar to Express, but with a few differences (mainly internally).

Here we have a simple example of a Hello World server, which listens on port 3000.

import bnnuy from 'bnnuy';

bnnuy()
    .get('/', async (_req, res) => {
        res.send('Hello World!');
    })
    .listen(3000);

And now here's another example, but this time we're serving static files from the public directory.

import bnnuy from 'bnnuy';

bnnuy()
    .static('public').
    .get('/', async (_req, res) => {
        res.send('Hello World!');
    })
    .listen(3000);

This still looks pretty much the same to Express, but the static middleware is actually a static middleware, meanwhile, the get method is a router middleware.

Middleware concepts

To handle requests faster than a normal Middleware based framework, Bnnuy uses a concept called middleware types.

These types tells Bnnuy how to handle the middleware, and what to do with it.

For now, there are 4 types of middleware:

  • basic middleware
  • static middleware
  • router middleware
  • error middleware

Basic middleware

This middleware is the classic concept of middleware, it's a function that takes 3 arguments: req, res and next.

  • req is the request object, which contains all the information about the request.
  • res is the response object, this tells Bnnuy how to respond to the request.
  • next is a function that tells Bnnuy to continue to the next middleware.

These middlewares are called on every request, and are usually used for logging, authentication, etc.

They're called with any request method, and any path.

Static middleware

As the name suggests, this middleware is used to serve static files. The difference with the basic middleware is that it doesn't take a next argument, and it's only called if the file exists.

The O-notation of this middleware is O(1), because it doesn't need to iterate over all the middlewares.

They're called only with the GET method.

Routing middleware

This middleware is used to handle requests to a specific path. It's similar to the basic middleware, but it doesn't take a next argument, and it's only called if the path matches the request path.

Error middleware

This middleware is used to handle HTTP errors. It's similar to the basic middleware, but it takes other arguments: err, req and res.

  • err is the error object, which contains all the information about the error.
  • req is the request object, which contains all the information about the request.
  • res is the response object, this tells Bnnuy how to respond to the request.

These middlewares are called only when the response status code is 4xx or 5xx and the response body is empty.

Contributing

All help is highly appreciated!

You can open an issue or a pull request, and I'll try to respond as soon as possible.

License

This project is licensed under the LGPL-3.0 license. See the LICENSE file for more information.