like the brain's powerful neural pathways, simple yet strong.
Axon is a backend library who tries to be simple and powerfull.
Currently Axon is 2X faster than Express. :D please checkout Axon Benchmarks
Latest change:
Install Axon.js with npm
npm install @mr-mkz/axon
You can checkout Axon benchmarks document and results from below link.
More features soon...
Currently Axon has a main core and a router class which you can make instance from router class every where you want and then gave the router instance to core to load routes.
More complete examples:
Router is stil under constructing and it's not a stable version yet but currently it support this methods:
You can access and create routes with just a few steps.
Router()
function in it. const router = Router()
router.get(path, controller(req, res))
loadRoute()
function;
const core = Axon(); // easier and newer method
// or
// const core = new AxonCore();
core.loadRoute(router)
you have to pass your controller to your route, compute and do your jobs in controller and when you want to response to user (each response, error and success) you must return res with some options which example and description for each option is below.
res.{option}
Options:
Example:
const controller = async (req, res) => {
return res.status(200).body({
message: "Hello, World"
})
}
middleware is a function which runs before running controller for validations or some actions like this and you can use it in two ways.
router.get('/', controller).middleware(async (req, res, next) => next());
you can also use multiple middlewares for a route by repeating middleware function and middlewares will run in order. core.globalMiddleware(async (req, res, next) => next());
you can also use multiple middlewares in this way by adding middleware functions into an array (suggested method) or repeating this line of code.AxonJs has some types which can help you in developing your applications for auto suggestions of your code editor.
Types detect automatically in Typescript but you need to set types for IDE suggestions in Javascript (Javascript Example).
AxonCoreConfig
: Type of core config object for configuration Axon core as you want.AxonResponseMessage
: Type of core config option RESPONSE_MESSAGES.AxonCorsConfig
: Type of core config option CORS.AxonHttpsConfig
: Type of core config option HTTPS.Request
: Type of controller request param. (IncomingMessage)Response
: Type of controller response param. (ServerResponse)Headers
: Type of response headers. (OutgoingHeaders)nextFn
: Type of next function param in middleware.Controller
: Type of controller function.Middleware
: Type of middleware function.you can config Axon core with loadConfig
method.
if you want to have ide suggestions for core config use AxonCoreConfig type.
Usage:
core.loadConfig({
LOGGER: false
})
Configs:
DEBUG
: boolean to set debug mode of core. (default false)LOGGER
: boolean to set core logger on or off. (default true)LOGGER_VERBOSE
: boolean to set core logger in verbose mode. (default false)RESPONSE_MESSAGES
: object to change default value of some core responses. (type: AxonResponseMessage)CORS
: object to change core cors settings. (type: AxonCorsConfig)HTTPS
: object to config server for https. (type: AxonHttpsConfig)listen
method runs your webserver.
If you want to run your server on https, you have to set key and cert file in HTTPS config of core to run https server automatically by core
core.loadConfig({
HTTPS: {
key: fs.readFileSync(path.join("server.key")),
cert: fs.readFileSync(path.join("server.crt"))
}
})
core.listen()
has some default values
core.listen("0.0.0.0", 80, () => {
console.log("server is running on port 80")
});
Contributions are always welcome!