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

velocy

v0.0.13

Published

A blazing fast, minimal backend framework for Node.js

Downloads

66

Readme

Velocy

A blazing fast, minimal backend framework for Node.js

Install the package

npm i velocy
# or
yarn add velocy

Import the Router class, and the createServer utility -

const { Router, createServer } = require("velocy");

Initialize the router

const router = new Router();

Register an endpoint

router.get("/", (req, res) => res.end("Hello, world!"));

// Or add dynamic parameters
router.get("/api/:version/user/:userId", (req, res) => {
    const { version, userId } = req.params;
    res.end(`API version: ${version}, User ID: ${userId}`);
});

// add a catch-all route
router.get("*", (req, res) => res.end("404 Not Found"));

Start the server

createServer(router).listen(3000);

Print the entire route tree (for debugging only):

  • Shows the name of the function if a named function is passed as a callback
  • Shows the function body trimmed down to 30 characters if used an anonymous function
router.get("/", function base_route(req, res) {});

router.get("/:id", function get_base_route_id(req, res) {});
router.get("/nope", function get_base_route_id(req, res) {});
router.post("/submit", function post_base_route_submit(req, res) {});
router.get("/hello/:name", (req, res) => {});
router.get("/hello/world", function get_hello_world(req, res) {});
router.post("/hello/world", function post_hello_world(req, res) {});

router.printTree();

The tree output:

Tree

Merge routers

const { Router, createServer } = require("velocy");

function getUserList(req, res) {
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end("/users: " + JSON.stringify({ users: ["Ishtmeet", "Jon"] }));
}

function showUserInfo(req, res) {
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end("/users/:id: " + JSON.stringify({ user: req.extractedParams.id }));
}

function teamsList(req, res) {
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end("/teams: " + JSON.stringify({ teams: ["Team Red", "Team Blue"] }));
}
const base_routes = new Router().get("/", (req, res) => {
    res.writeHead(200, { "Content-Type": "text/plain" });
    res.end("Hello World");
});

const user_routes = new Router().get("/users", getUserList).get("/users/:id", showUserInfo);
const team_routes = new Router().get("/teams", teamsList);

const main_router = new Router();
main_router.merge(user_routes);
main_router.merge(team_routes);
main_router.merge(base_routes);

// Response
// GET /            -> Hello world
// GET /users       -> {"users":["Ishtmeet","Jon"]}
// GET /users/:id   -> {"user":"1"}
// GET /teams       -> {"teams":["Team Red","Team Blue"]}

Nest routers

const { Router, createServer } = require("velocy");

function getUserList(req, res) {
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end("/users: " + JSON.stringify({ users: ["Ishtmeet", "Jon"] }));
}

function showUserInfo(req, res) {
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end("/users/:id: " + JSON.stringify({ user: req.extractedParams.id }));
}

function teamsList(req, res) {
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end("/teams: " + JSON.stringify({ teams: ["Team Red", "Team Blue"] }));
}
const base_routes = new Router().get("/", (req, res) => {
    res.writeHead(200, { "Content-Type": "text/plain" });
    res.end("Hello World");
});

const user_routes = new Router().get("/users", getUserList).get("/users/:id", showUserInfo);
const team_routes = new Router().get("/teams", teamsList);

const main_router = new Router();
main_router.merge(user_routes);
main_router.merge(team_routes);
main_router.merge(base_routes);

const api_router = new Router();
api_router.nest("/api/v1", main_router);

createServer(api_router).listen(3000, () => {
    console.log("Server is running on port 3000");
});

// Response
// GET /api/v1             -> 404 Not Found
// GET /api/v1/            -> Hello world
// GET /api/v1/users       -> {"users":["Ishtmeet","Jon"]}
// GET /api/v1/users/:id   -> {"user":"1"}
// GET /api/v1/teams       -> {"teams":["Team Red","Team Blue"]}