jesusvilla / natural Goto Github PK
View Code? Open in Web Editor NEWFastest Framework for NodeJS. Written in pure ES6+
License: GNU General Public License v3.0
Fastest Framework for NodeJS. Written in pure ES6+
License: GNU General Public License v3.0
I would like to draw your attention to the code that is here on github.
I imagine this code is functional by cloning the repo. I think the ideal is that the examples are based on an application with naturaljs installed via npm.
I loaded the natural js module via require instead of import and it worked great
my code was like this:
const { readFile } = require('fs/promises');
const NaturalRouter = require('natural-framework/lib/router');
// --> const { HttpServer } = require('uWebSockets.js/uws');
// const { HttpServer } = require('natural-framework/lib/server');
function createRoutes (router) {
router
.get('/fillbuffer', (_, response) => {
response.send({ result: 'Hello world' }, 'json');
})
.get('/file', async (_, response) => {
const content = await readFile('./file.txt');
response.send({ result: content.toString() }, 'json');
});
}
async function bootstrap () {
const router = new NaturalRouter({
// type: 'node', // for Node.js native application - default is 'uws'
// server: HttpServer // not necessary ?!?!
/* ssl: {
key: path.join(__dirname, './security/cert.key'),
cert: path.join(__dirname, './security/cert.pem')
} */
});
try {
createRoutes(router);
const port = await router.listen(53008);
console.log(`Listen http://localhost:${port}`);
} catch (error) {
console.log('Error:', error);
}
}
bootstrap();
I got to know naturaljs-router by checking the list from web-frameworks-benchmark.netlify.app
I've been following the dev of hyper-express, also based on uWebSockets.js.
I theoretically made the same codes as simple as possible with:
I used ab (Apache Benchmark) and autocannon to get the numbers and I was surprised by the performance of the naturaljs that was side by side with the app in GoLang, the latter using keepalive.
using 127.0.0.1 instead of localhost, requests with excellent maximum times did not fail. really nice job!
sorry I am getting boring :-)
if I understand correctly, you are using Babel to convert ES6+ code. why not leave it in ES6+ pure ?
Hi @jesusvilla,
The uWeSockets
version used
Line 68 in cdc8c6e
node
last LTS, 18.12
/usr/src/app/node_modules/uWebSockets.js/uws.js:22
throw new Error('This version of µWS is not compatible with your Node.js build:\n\n' + e.toString());
^
Error: This version of µWS is not compatible with your Node.js build:
Error: Cannot find module './uws_linux_x64_108.node'
Require stack:
- /usr/src/app/node_modules/uWebSockets.js/uws.js
- /usr/src/app/node_modules/natural-framework/lib/router/types/uws.js
- /usr/src/app/node_modules/natural-framework/lib/router/index.js
- /usr/src/app/app.js
at /usr/src/app/node_modules/uWebSockets.js/uws.js:22:9
at Object.<anonymous> (/usr/src/app/node_modules/uWebSockets.js/uws.js:24:3)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/usr/src/app/node_modules/natural-framework/lib/router/types/uws.js:3:13)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
Node.js v18.12.1
Regards,
Related to the-benchmarker/web-frameworks#5968
hi Jesus. nice work!! natural are so fast as Go with fasthttp: 195K reqs/sec.
Is it possible to use async/await in handles ?
from:
function createRoutes (router) {
router
.get('/show', (_, response) => {
doQueryDB({}, (err, data) => {
if(!err) response.send({ result: data }, 'json');
});
});
}
to:
function createRoutes (router) {
router
.get('/show', async (_, response) => {
const data = await doQueryDB({});
response.send({ result: 'Hello world1' }, 'json');
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.