Hello developers! π
I'm excited to introduce you to AxonJs, a new backend framework designed to simplify and accelerate the development of RESTful APIs. As the creator of AxonJs, I developed this framework to address the complexities and limitations I've encountered with existing solutions like Express.js. AxonJs aims to provide a more structured, performant, and developer-friendly approach to building backend applications.
π Why AxonJs?
While Express.js has been a staple in the Node.js ecosystem, it often requires additional libraries and boilerplate code to achieve a well-structured application. AxonJs addresses these challenges by offering:
Built-in Structure: Encourages a modular architecture with clear separation of concerns.
Enhanced Performance: Benchmarks indicate that AxonJs is up to twice as fast as Express.js.
Developer Experience: Provides a suite of tools and conventions to streamline development.
π§ Key Features
-
Modular Routing System
AxonJs introduces a flexible routing mechanism that allows you to define routes in separate files and load them into the core application seamlessly.
const router = Router('api'); router.get('/users', getUsersController); router.post('/users', createUserController); core.loadRoute(router);
-
Middleware Support
Easily add middleware functions globally or to specific routes, facilitating tasks like authentication, logging, and validation.
// Global middleware // structure: (middleware, timeout, isCritical) core.globalMiddleware(authMiddleware, 1000, true); // Route-specific middleware router.get('/admin', adminController) .middleware(adminMiddleware, 1000, true);
-
Integrated Logger
Leverages pino and pino-pretty for efficient and readable logging. You can access the logger instance throughout your application.
import { axonLogger } from '@axonlabs/core'; axonLogger.info('Server started successfully');
Plugin System
Extend AxonJs functionality by creating and integrating custom plugins, promoting code reuse and modularity.TypeScript Support
Written in TypeScript, AxonJs offers type definitions and interfaces to enhance code reliability and editor support.-
HTTPS and CORS Configuration
Simplify the setup of secure servers and cross-origin resource sharing with built-in configuration options.
// axon.config.js / mjs / cjs / ts module.exports = { HTTPS: { key: fs.readFileSync('server.key'), cert: fs.readFileSync('server.crt'), }, CORS: { origin: '*', methods: ['GET', 'POST'], }, };
-
Auto validation handler
Axon has auto validation handler for routes and just you need to pass your Yup, Joi or Zod schema to Axon and it automatically add middleware and handle all validations.The structure is:
router.method("route", controller, [Array of validation objects]) validationObj = { schema: "validation schema", options: "Schema options (object)", target: "body" | "params" | "query" // valiation target } // =====================Example====================== // Create your schema (Joi, Yup, Zod) const bodySchema = Joi.object({ username: Joi.string().min(3).required(), age: Joi.number().integer().min(0).required() }); router.post('/user/{id}', async (req, res) => { return res.status(201).body({ message: 'Body data is valid!', data: { body: req.body } }) }, [ { schema: bodySchema, target: "body", options: { abortEarly: false } as Joi.ValidationOptions } ])
βοΈ Installation and Setup
Install AxonJs core and CLI:
npm install @axonlabs/core
npm install -g @axonlabs/cli
Create a new project:
axon create:project
Start the server:
import { Axon } from "@axonlabs/core";
const core = Axon();
core.listen('0.0.0.0', 3000, () => {
console.log('Server is running on port 3000');
});
π Performance Comparison
In benchmark tests, AxonJs demonstrated superior performance compared to Express.js, handling twice the number of requests per second under similar conditions. This efficiency is achieved through optimized routing and middleware processing.
π€ Join the Community
AxonJs is an open-source project, and I invite you to be part of its growth. Whether youβre a seasoned developer or just starting, your contributions, feedback, and ideas are welcome.
GitHub: AxonJsLabs/AxonJs
Telegram Channel: t.me/axonjs
Letβs collaborate to build a robust and supportive community around AxonJs!
π§βπ» About the Author
Iβm Mr.MKZ, a passionate developer focused on creating tools that enhance the developer experience. AxonJs is the culmination of my efforts to provide a better framework for building RESTful APIs. I look forward to your feedback and contributions to make AxonJs even better.
Thank you for taking the time to learn about AxonJs. I hope it becomes a valuable tool in your development toolkit. Happy coding! π
Top comments (0)