
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
An OOP style declare Nodejs framework base on Express.js!
An OOP Style Restful Api framewrok base on Express.js,and make Nodejs development beautiful and easy.
项目 | Mkbug.js | Egg.js | Think.js |
---|---|---|---|
Nodejs | Nodejs 10+ | Nodejs 8+ | Nodejs 6+ |
Base on | Express.js | Koa.js | Koa.js |
Router | Auto | Manual | Auto |
Plugin | Auto | Manual | Manual |
Middleware | Auto+Manual | Manual | Manual |
Config | Auto | No | No |
JS extend | ES6 | ES6 | Babel |
Style | OOP | Pure | Pure |
Duration | Yes | No | No |
Extend Capability | compatible expressjs | egg ecology | compatible koa |
// index.js
const express = require('express');
const app = express();
const { Mkbug } = require('mkbugjs');
new Mkbug(app)
.create('/') // 请求url前缀
.use(bodyParser.json()) // 使用express中间件
.start(3001, (err) => { // 启动,同app.listen
if (!err)
console.log('Server started!')
else
console.error('Server start failed!')
})
// src/controller/index.js
const { BaseController } = require('mkbugjs');
module.exports = class api extends BaseController {
getAction () {
return 'Hello World';
}
}
If you want to use middleware like koa. you can use it like this.
// base/ControllerBaseBase.js
const { BaseController } = require('mkbug.js');
module.exports = class ControllerBaseBase extends BaseController {
before (req) {
console.log("ControllerBaseBase before")
}
after(){
console.log("ControllerBaseBase after")
}
}
// base/ControllerBase.js
const ControllerBaseBase = require('./ControllerBaseBase');
module.exports = class ControllerBase extends ControllerBaseBase {
before (request, response) {
super.before(request, response)
console.log("ControllerBase before")
}
after ({ duration, status, originalUrl, request, response }) {
console.log("ControllerBase after")
super.after({ duration, status, originalUrl, request, response })
}
}
// ExtendsTest.js
const ControllerBase = require('./base/ControllerBase');
module.exports = class ExtendsTest extends ControllerBase {
before (request, response) {
super.before(request, response)
console.log("Request start")
}
getAction () {
return "hello world"
}
after () {
console.log("Request end")
super.after({})
}
}
And then you can send curl request to /api/extendstest, you should get the log:
$ curl http://localhost:3000/api/extendstest
ControllerBaseBase before
ControllerBase before
Request start
Request end
ControllerBase after
ControllerBaseBase after
It is very easy, right?
FAQs
An OOP style declare Nodejs Web framework base on Express.js
The npm package mkbugjs receives a total of 4 weekly downloads. As such, mkbugjs popularity was classified as not popular.
We found that mkbugjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.