Giter Club home page Giter Club logo

natural's People

Contributors

jesusvilla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

natural's Issues

examples

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();

performance & benchmark

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:

  • fastify 4,
  • polkadot,
  • hyper-express,
  • naturaljs
  • and in GoLang with fasthttp.

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!

another question

sorry I am getting boring :-)

if I understand correctly, you are using Babel to convert ES6+ code. why not leave it in ES6+ pure ?

Not available for last LTS

Hi @jesusvilla,

The uWeSockets version used

"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.8.0"

is not available on 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

routes with async/await

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');
    });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.