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

exha

v1.2.11

Published

Fast, compact, open source route and middleware handler for expess

Downloads

13

Readme

Exha

Fast, compact, open source route and middleware handler for expess

Fast Setup

npx exhapack your_app_name
//index.js
const { Exha } = require("exha");
const exha = new Exha();

exha.init();

Installation

This is a Node.js module avaliable on the npm registry

Installation is done using the:

$ npm install --save-dev exha

Features

  • Easily file routings
  • Easily file middlewares for routings
  • Create application quickly
  • Built-in image uploader

Table of Contents

Setup

Create a /root directory, create index.js file, create exha.config.js file, create /routes directory and create /index file in routes directory

Looks like;

project_root/
│
├── /routes
│   └── index.js
│
├── exha.config.js
│
└── index.js

project_root/index.js

const { Exha } = require("exha");
let exha = new Exha();

exha.init();

project_root/exha.config.js

exports.default = {
    port: 3000,
    routeDir: "/routes",
};

project_root/routes/index.js

module.exports = {
    event: (req, res) => {
        res.send("Hello world");
    },
};

Middleware uses

Add middlewareDir properties to exha config

exports.default = {
    port: 3000,
    routeDir: "/routes",
    middlewareDir: "/middlewares",
};

and create a new middleware in /middlewares directory

project_root/middlewares/check.js

module.exports = {
    middleware: (req, res, next) => {
        console.log("A new request!");
        next();
    },
};

and go back to routes/index

const {mwLoader} = require("exha")
let checkMw = mwLoader("check.js")

module.exports = {
    middlewares = [checkMw],
    event: (req,res) => {
        res.send("Hello world")
    }
}

Plugin uses

Plugin usage is very similar to middleware. Add pluginDir properties to exha config

exports.default = {
    port: 3000,
    routeDir: "/routes",
    middlewareDir: "/middlewares",
    pluginDir: "/plugins",
};

and create a new plugin in /plugins directory

project_root/plugins/whoReq.js

module.exports = {
    plugin: (name) => {
        console.log(name, " requested");
    },
};

and go back to routes/index

const {mwLoader,plLoader} = require("exha")
let checkMw = mwLoader("check.js")
let whoReq = plLoader("whoReq.js")

module.exports = {
    middlewares = [checkMw],
    event: (req,res) => {
        whoReq("John Doe")
        res.send("Hello world")
    }
}

Form parsing

Allows parsing of incoming requests

Add parseForm properties to exha config

exports.default = {
    port: 3000,
    routeDir: "/routes",
    middlewareDir: "/middlewares",
    pluginDir: "/plugins",
    parseForm: true,
};

Static files

Serving static files

Add staticDir properties to exha config

exports.default = {
    port: 3000,
    routeDir: "/routes",
    middlewareDir: "/middlewares",
    pluginDir: "/plugins",
    parseForm: true,
    staticDir: "public",
};

Image uploader

Built-in image uploader

Add imageUploader properties to exha config

exports.default = {
    port: 3000,
    routeDir: "/routes",
    middlewareDir: "/middlewares",
    pluginDir: "/plugins",
    parseForm: true,
    staticDir: "public",
    imageUploader: true,
};

Use can it in middleware

const {mwLoader,plLoader,uploader} = require("exha")
let checkMw = mwLoader("check.js")
let whoReq = plLoader("whoReq.js")

module.exports = {
    middlewares = [checkMw,uploader.single("image")],
    event: (req,res) => {
        console.log(req.files)
        whoReq("John Doe")
        res.send("Hello world")
    }
}