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

vikhola

v2.0.0

Published

Event-driven framework for HTTP applications

Downloads

64

Readme

About

Vikhola offers an event-driven framework for HTTP applications with high performance and scalability.

Why?

Events offer objects with a known API that will be sent to listeners who subscribe to them. Listeners, in turn, become independent services which, in addition to improving testability because of well-known API, are also easily replaceable. This helps to have confidence in the data during processes, which is especially important for a weakly and dynamically typed language as javascript.

Installation

$ npm i vikhola

Quick start

Package could be required as ES6 module

import { Server } from 'vikhola';

Or as commonJS module.

const { Server } = require('vikhola');

First Server

The application starts by creating a server instance and adding the first route with a controller bound to it.

// Require the framework and instantiate it
const { Server } = require('vikhola');
const server = new Server();

// Declare a route
server.get('/', function (ctx) {
	ctx.response.send({ message: 'Hello World!' });
});

Route controller can be both sync and async.

server.get('/', async function (ctx) {
	// some async logic
	ctx.response.send({ message: 'Hello World!' });
});

After the route and its controller declaration first server is ready to go!

// Run the server!
server.listen(3000);

First Events

As mention before the vikhola framework provides its own events that will be emitted at different stages of request lifecycle. This example is uses "kernel.request" event, which will be executed before the controller, and "kernel.response", which will be executed after it.

// Declare a listeners
server
.on('kernel.request', function(event) {
    console.log('executes before controller.');
})
.on('kernel.response', function(event) {
    console.log('executes after controller.');
});

server.get('/', function (ctx) {
    console.log('controller.');
});

server.listen(3000);

Besides of server instance, listeners can listen for events on a specific route. This can be done by adding them to the route instance.

// Declare a global listeners 
server.on('kernel.request', function(event) {
    console.log('executes at every request.');
});

const route = server.get('/foo', function (ctx) {
    console.log('controller.');
});

// Declare a route scope listeners 
route.on('kernel.request', function(event) {
    console.log('executes only at this route request.');
}, { priority: 10 });

server.listen(3000);

At this example route scope listener executes before the global listener because of its priority. You can read about events, listeners and their options in the provided documentation.

Documentation

This is only a piece of functionality which provides vikhola framework to learn more you can follow documentation:

License

MIT