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

orbty

v0.9.8

Published

Simple and high performance web server structure for

Downloads

35

Readme

orbty

Simple and high performance web server structure for building scalable, practical and fast server applications.

const Orbty = require("orbty");
orbty = new Orbty();

orbty.get("/welcome", ({ query }) => {
  return { hello: "world" };
});

orbty.listen(8080)

Installation

Installation is easy with the npm command

$ npm install orbty

Current features

  • High test coverage.
  • Middlewares support.
  • Compatible with Typescript.
  • Compatible with express middleware.
  • Automatic HTTP error handler.
  • Integrated body-parser.
  • Dynamic url.
  • High performance.
  • Static files.
  • Support routing by instance.
  • Compatible with your native server. (HTTP, HTTPS).

Examples

Define how the data will be sent in the response.

Basic


// use simple function return
orbty.post("/post/:id", Orbty.json(), ({ body, params }) => {
  return {
    id: params.id,
    content: body.content
  };
});

// use response
orbty.post("/post/:id", (req, res) => {
  res.json({
    id: req.params.id,
    content: req.body.content
  });
});

Errors

Orbty gives you the possibility to treat errors as you see fit. We recommend using the HttpException:

orbty.get("/", (req, res) => {
  throw new Orbty.HttpException("Message error");
});

Set HTTP response status:

orbty.get("/posts/:id", ({ params }) => {
  if (params.id === "1") {
    return "found";
  }

  throw new Orbty.HttpException("Post not found", 404);
});

Create your own errors with your own status codes. Set code attribute with HTTP status:

class NotFound extends Orbty.HttpException {
  constructor(message) {
    super(message, 404);
  }
}

Use:

orbty.get("/posts/:id", ({ params }) => {
  if (params.id === "1") {
    return "found";
  }

  throw new NotFound("Post not found");
});

Or use single response:

orbty.get("/posts/:id", ({ params }, res) => {
  if (params.id === "1") {
    return "found";
  }

  res.status(404).send("Post not found");
});

Capture error handlers:

orbty.error((error, req, res) => {
  console.error(error);
});

Middlewares

Orbty is compatible with all your favorite express middleware and the syntax is the same. We decided to keep the same syntax for its familiarity and simplicity.

const Orbty = require("orbty");
const middleware = require("my-middleware");

const orbty = new Orbty();

orbty.use(middleware);

// ...

The body-parser middleware already integrated with Orbty.

const Orbty = require("orbty");
const orbty = new Orbty();

orbty.post("/posts", Orbty.json({ extended: true }), ({ body }) => {
  return body;
});

orbty.post("/posts/comment", Orbty.text(), ({ body }) => {
  return body;
});

// ...

Static files

Send static files through your api. Orbty contains a middleware that solves this easily:

const Orbty = require("orbty");
const orbty = new Orbty();

orbty.use(Orbty.static(`${__dirname}/media`));
orbty.use(Orbty.static(`${__dirname}/photos`));

// ...

Cache

We currently have a separate Cache management module for Orbty and also compatible with Express. Check orbty-http-cache.

Orbty instancies

An Orbty instance acts as a router.

const Orbty = require("orbty");

const orbty = new Orbty();
const orbtyV2 = new Orbty();

orbtyV2.get("/", () => "This is v2 API");

orbty.use("/v2", orbtyV2);

Https

Use Orbty with https and others http protocols:

const https = require("https");
const Orbty = require("orbty");
const fs = require("fs");

const orbty = new Orbty();

orbty.get("/", () => {
  return "this secure server";
})

// Node JS native documentation
const options = {
  key: fs.readFileSync("secury.pem"),
  cert: fs.readFileSync("secury-cert.cert")
};

https.createServer(options, orbty.server()).listen(443);

TODO

  • Improve documentations on external page
  • Improve stream