Introduction to Nomi.js: A Node.js Micro Framework for Backend Development
This article introduces Nomi.js, a lightweight Node.js micro‑framework built on Koa2, explains its design goals and pain‑points it solves, outlines its key features, and provides step‑by‑step instructions with code examples for installing the CLI, initializing a project, and creating MVC‑style controllers and services.
This article introduces Nomi.js, a Node.js micro‑framework developed by Qunar that is built on Koa2 and designed for enterprise‑level microservice applications.
What is Nomi?
Nomi.js (Node micro framework) is a highly modular, low‑intrusion framework that offers high stability, modularity, and task separation, making it ideal for building RESTful APIs and microservices.
Pain points solved by Nomi
Provides a clear target scenario for enterprise team development and microservice construction.
Zero‑intrusion design allows existing business code to be migrated without refactoring.
Offers customizable engineering constraints to keep project structure consistent across teams.
Middleware and plugin loaders enable plug‑and‑play extensions without rebuilding the ecosystem.
Focuses developers on business logic rather than framework boilerplate.
Key Features
Multi‑module development support
RESTful API support
Weakly intrusive design
Customizable engineering constraints
Async/await support
Elegant syntax sugar for cleaner code
How to start a Nomi service
First, install the nomi-cli scaffolding tool: npm i nomi-cli -g Then build your application with the following commands:
1. nomi-cli init // initialize project
2. cd <project> && npm i // install dependencies
3. npm run build // compile
4. npm start // start Nomi serviceAfter the setup, you can access the service at http://127.0.0.1:8080/order/detail/2 to see the response.
Creating a Controller (MVC pattern)
Create app/controller/OrderController.js with the following content:
/**
* Controller example
* File: app/controller/OrderController.js
* Description: Order controller class example
*/
const { RequestMapping, Service } = require('nomi-router').notation;
@RequestMapping({ path: "/order" })
class OrderController {
@Service('service.orderService')
serviceInst;
@RequestMapping({ path: "/detail/{orderNum:string}", method: "get" })
async getOrderDetail(req, res, params, ctx) {
res.body = await this.serviceInst.getDetail(params.orderNum);
}
}
exports.OrderController = OrderController;Creating a Service
Create app/service/OrderService.js:
/**
* Service example
* File: app/service/OrderService.js
* Description: Order service class example
*/
const { Service } = require('nomi-router').notation;
@Service("service.orderService")
class OrderService {
async getDetail(orderNum) {
// Call remote procedure or query database (shown later)
let result = {};
// result = await ctx.curl(`http://javaServer.com/order/detail/${orderNum}`, { dataType: 'json' });
return result.data || { orderNum };
}
}
exports.OrderService = OrderService;Review
In summary, three steps get a Nomi application running: install the CLI, write a controller, and write a service. Nomi’s syntax sugar such as @RequestMapping and @Service simplifies routing and dependency injection, allowing developers to focus solely on business logic. For more advanced features, refer to the advanced tutorial.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
