jesusvilla/natural

examples

Closed this issue · 1 comments

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

sorry. I have looked to developer branch. I checked the master branch and I see the correct example. disregard my comment please