exha
v1.3.0
Published
Fast, compact, open source route and middleware handler for expess
Downloads
152
Maintainers
Readme

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 exhaFeatures
- 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.jsproject_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,
};Change source directory
Change the project source directory
exports.default = {
port: 3000,
routeDir: "/routes",
middlewareDir: "/middlewares",
pluginDir: "/plugins",
parseForm: true,
staticDir: "public",
imageUploader: true,
sourceDir:"src/"
};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")
}
}