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();
This is a Node.js module avaliable on the npm registry
Installation is done using the:
$ npm install --save-dev exha
- Easily file routings
- Easily file middlewares for routings
- Create application quickly
- Built-in image uploader
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");
},
};
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 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")
}
}
Allows parsing of incoming requests
Add parseForm
properties to exha config
exports.default = {
port: 3000,
routeDir: "/routes",
middlewareDir: "/middlewares",
pluginDir: "/plugins",
parseForm: true,
};
Serving static files
Add staticDir
properties to exha config
exports.default = {
port: 3000,
routeDir: "/routes",
middlewareDir: "/middlewares",
pluginDir: "/plugins",
parseForm: true,
staticDir: "public",
};
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")
}
}