# Introduction
# 1 Introduction
Sener is a simple, efficient, powerful, and highly scalable nodejs web server framework The core of Sener is a simple http server. With built-in request and response parsing and a highly flexible middleware system, developers can develop feature-rich and powerful web applications based on Sener.
Feedback Issues (opens new window)
# 2. Features
- Simple and efficient architecture, fully written in TS, highly friendly TS declaration support
- Supports a highly customized and highly scalable middleware system, using the onion model and rich routing hooks
# 3. Middleware
Name | Type | Function | Supported Version |
---|---|---|---|
router | built-in | simple and highly scalable routing rules | 0.0.3 |
cookie | built-in | for cookie fetching and injection | 0.0.15 |
session | built-in | for session acquisition and injection [depends on cookie] | 0.0.15 |
cors | built-in | support for cross-origin requests | 0.0.3 |
env | built-in | for injecting and using environment variables | 0.0.15 |
ip-monitor | built-in | used for risk control interception of request ip | 0.0.15 |
validator | built-in | supports validating input parameters and parameter type definitions | 0.0.15 |
json | standalone | support json files for data storage | 0.0.4 |
static | standalone | support static file directory | 0.0.14 |
form | Standalone | Support formdata parsing and file upload | 0.0.11 |
config | independent | supports highly flexible parameter configuration and dynamic change and monitoring | 0.0.11 |
log | Independent | Support flexible log system, support log level control | 0.0.11 |
mysql | standalone | support mysql connection | 0.0.12 |
mongodb | standalone | support mongodb connection, collocation encapsulation | 0.0.12 |
rpc | stand-alone | remote call support, support client and server use, support x-trace-id injection request | 0.0.13 |
The built-in middleware is the middleware that comes with the sener package, but it needs to be manually introduced when using it
To use the independent middle, you need to install the corresponding independent package
# 4. Basic use
import { Sener, Router } from 'sener';
const router = new Router({
'/demo': ({ query }) => {
// or: 'get:/demo': ({ query }) => { // get: prefix can be ignored
query.message = 'from get';
return { data: query };
// Custom headers or statusCode
// return { data: query, headers: {}, statusCode: 200 };
},
'post:/demo': async ({ body }) => {
body. message = 'from post'
return { data: body };
},
});
new Sener({
port: 9000,
middlewares: [router],
});
If it is used directly by nodejs, please use the cjs specification reference
const { Sener, Router } = require('sener');
The esm specification is used in the following documents, and the default port is 9000. If you need cjs, please modify it yourself