A minimal server middleware composer for the future. Mostly, It is used to create http server and handle proxy. The interesting part is that it also works fine without any ES6 or ES7 syntax, it's up to you to decide how fancy it will be. And because its middlewares are just normal functions, they can be easily composed with each other.
To use noflow, you only have to remember a single rule "Any async function should and will return a Promise".
- Super lightweight, only one dependency, 200 sloc, learn it in 5 minutes
- Static-typed with typescript
- Faster than Express.js and Koa, see the benchmark section
- Based on Promise, works well with async/await
- Supports almost all exist Express-like middlewares
For examples, goto folder examples.
To run the examples, you have to install the dependencies of this project:
Such as, to run the examples/basic.js, use command like:
npm i noflow.
Hello World Example
;let app = ;// Anything pushed into the app will be converted to a// middleware object sanely, even it's a string, buffer, stream or anything else.// Here we created a server that responses only string "hello world".app;app;
Without ES7, you can still have all the goodies.
var flow = default;var app = ;app;app;app;
Designed for the future ES7.
;let app = ;app;app;
You can write routes quickly by using select interface of NoKit.
;;let match select = kit;let app = ;app;app;
It's easy to convert an express middleware to noflow middleware.
;;let app = ;let;app;app;
It's recommended to use typescript to check all the API details.
Create an array instance with some handy server helper methods.
FlowArray middlewares Optional. If not provided, the return type will be a FlowArray, else a middleware Function.
FlowArray | Function
example:let app = ;app;app;
Noflow will auto handle status code
500 for you only if
you haven't set the status code yourself.
204: If you don't set
$.body, such as it's
404: If no middleware found.
500: If any middleware reject or throws an error.
userDefined: If user set the
200: If none of the above happens.
A middleware can catch all the errors of the middlewares after it.
With ES5, you can use it like normal promise error handling:
var flow = default;var app = ;app;app;app;app;
With ES7, you can use try-catch directly:
;let app = ;app;app;app;
Noflow relies on the async nature of Promise, when you need async io tools, nokit will be the best choice. nokit has all the commonly used IO functions with Promise support.
For example you can use them seamlessly:
;;let select = kit;let app = ;app;app;
These comparisons only reflect some limited truth, no one is better than all others on all aspects.
You can run it yourself in terminal:
npm run no -- benchmark.
Node v5.4.0 The less the better: noflow: 1839.333ms koa: 2598.171ms express: 3239.013ms