Console

Having a good console to debug or test your code is always useful. node-nc is a very useful package to do just that. Similarly to rails console it globalizes your files and packages to be easily used.

To use seamlessly with orka a simple nc.js file could be:

process.env.NODE_ENV = 'console';
const { orka, getRabbit, getKafka } = require('@workablehr/orka');

global.orka = orka({
  // your custom configuration would go here
});
global.orka.initTasks().then(() => global.orka.initMiddleWare());

global.getRabbit = getRabbit;
global.getKafka = getKafka;

Checking config that it is reading env correctly

npx node-nc
> npx: installed 13 in 2.556s
> @workablehr/orka> config
> {
>   nodeEnv: 'demo',
>   log: { json: true },
>   app: { name: 'foo' },
>   cors: { publicPrefixes: [ '/api/allowAll' ] },
>   riviere: { bodyKeysRegex: '.*' }
> }

Checking that a route is matched correctly

npx node-nc
> orka.defaultRouter.matching('/testGet', 'GET')
> {
>   ctx: {
>     path: '/testGet',
>     method: 'GET',
>     params: {},
>     _matchedRoute: '/testGet'
>   },
>   middlewares: [ [AsyncFunction], [AsyncFunction] ]
> }

Publishing messages to RabbitMQ

npx node-nc
> getRabbit().publish('queue', {data:{}}, {correlationId:'test'})