0.0.2 • Published 2 years ago

codehux v0.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

CodeHux

A minimal Codehooks library.


The purpose of this library is to emulate the coding style of popular node frameworks like Express, Koa, Fastify, etc. and make it available as a utility when developing a project on Codehooks.

Example usage:

// index.js (main codehooks file)
const hux = require('codehux')();

const Cron = {
  EVERY_10_SECONDS: '*/10 * * * * *',
};

const Topics = {
  MAIN: 'MAIN',
};

hux.post('/endpoint', async (req, res) => {
  const conn = await DB.open();
  await conn.enqueue(Topics.MAIN, { task: req.body });

  res.end();
});

hux.queue(Topics.MAIN, async (req, res) => {
  const item = req.body.payload.task;

  console.log('Queue item:', item);

  res.end();
});

hux.job(Cron.EVERY_10_SECONDS, async (req, res) => {
  const conn = await DB.open();

  await conn.enqueue(Topics.MAIN, { task: 'Job Hook Says Hi :-)' });
  res.end();
});

export default hux.init();
0.0.2

2 years ago

0.0.1

2 years ago