
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Microservice framework based on native Node.js HTTP module and AMQP protocol (express integration as feature).
Microservice framework based on native Node.js HTTP module and AMQP protocol with express middleware & built-in prometheus. 🔬 🐇
$ npm i micromq
$ RABBIT_URL=amqp://localhost node tests/apps/users.js &
$ RABBIT_URL=amqp://localhost node tests/apps/balances.js &
$ RABBIT_URL=amqp://localhost PORT=3000 node tests/apps/gateway.js &
$ PORT=3000 npm test
There are some simple examples.
options <Object>
This method creates gateway.
const Gateway = require('micromq/gateway');
const gateway = new Gateway({
microservices: ['users', 'orders'],
rabbit: {
url: 'amqp://localhost:5672',
},
requests: {
timeout: 5000,
},
});
This method creates RPC action.
const Gateway = require('micromq/gateway');
const { Users } = require('./db');
const gateway = new Gateway({ ... });
gateway.action('increase_balance', async (meta, res) => {
if (!meta.amount || Number.isNaN(+meta.amount)) {
res.status(400);
res.json({ error: 'Bad data' });
return;
}
await Users.updateOne({
userId: meta.userId,
}, {
$inc: {
balance: meta.amount,
},
});
res.json({ ok: true });
});
gateway.listen(3000);
const MicroMQ = require('micromq');
const app = new MicroMQ({ ... });
app.post('/deposit', (req, res) => {
// send rpc action to the gateway
res.json({
server: {
action: 'increase_balance',
meta: {
userId: 1,
amount: 500,
},
},
});
});
app.start();
This method creates application event (read more).
const MicroMQ = require('micromq');
const app = new MicroMQ({ ... });
// register event
app.on('error', (err, req, res) => {
console.error(err); // 'Random error!'
});
app.use(async (req, res, next) => {
try {
await next();
} catch (err) {
res.status(err.status || 500);
res.json({ error: err.message || 'Server error' });
// emit event
app.emit('error', err, req, res);
}
});
app.post('/throw', (req, res) => {
throw 'Random error!';
});
app.start();
name <string> Event name...args <...any> - ArgumentsThis method emits application event.
This method enables prometheus monitoring.
const Gateway = require('micromq/gateway');
const gateway = new Gateway({ ... });
// start prometheus with default /metrics endpoint & without credentials
gateway.enablePrometheus();
// start prometheus with /users/metrics endpoint & without credentials
gateway.enablePrometheus('/users/metrics');
// start prometheus with /users/metrics endpoint & credentials
gateway.enablePrometheus('/users/metrics', {
user: 'admin',
password: 'admin',
});
// start prometheus with default /metrics endpoint & credentials
gateway.enablePrometheus({
user: 'admin',
password: 'admin',
});
gateway.listen(3000);
...middlewares <...function> MiddlewaresThis method adds middlewares.
This method creates endpoint for all HTTP-methods.
This method creates endpoint with needed method.
This method returns middleware for express.
const express = require('express');
const bodyParser = require('body-parser');
const Gateway = require('micromq/gateway');
const users = require('./routers/users');
const app = express();
const gateway = new Gateway({ ... });
app.use(bodyParser.json());
// apply middleware
app.use(gateway.middleware());
// monolith router
app.use('/users', users);
// delegate requests to the microservice
app.use('/orders', (req, res) => res.delegate('orders'));
port <number> Port for listen.This method creates HTTP-server and starts listen needed port.
options <Object>
This method creates microservice.
const MicroMQ = require('micromq');
const app = new MicroMQ({
microservice: 'users',
rabbit: {
url: 'amqp://localhost:5672',
},
});
This method creates RPC action.
const MicroMQ = require('micromq');
const { Users } = require('./db');
const app = new MicroMQ({ ... });
app.action('new_deposit', async (meta, res) => {
await Users.updateOne({
userId: meta.userId,
}, {
$inc: {
level: 1,
},
});
res.json({ ok: true });
});
app.start();
This method enables prometheus monitoring.
const MicroMQ = require('micromq');
const app = new MicroMQ({ ... });
// start prometheus with default /metrics endpoint & without credentials
app.enablePrometheus();
// start prometheus with /users/metrics endpoint & without credentials
app.enablePrometheus('/users/metrics');
// start prometheus with /users/metrics endpoint & credentials
app.enablePrometheus('/users/metrics', {
user: 'admin',
password: 'admin',
});
// start prometheus with default /metrics endpoint & credentials
app.enablePrometheus({
user: 'admin',
password: 'admin',
});
app.start();
...middlewares <...function> MiddlewaresThis method adds middlewares.
This method creates endpoint for all HTTP-methods.
This method creates endpoint with needed method.
name <string> Microservice for askquery <Object>
This method asks other microservice.
const MicroMQ = require('micromq');
const app = new MicroMQ({
...,
microservices: ['balances'],
});
app.get('/users/me/info', async (req, res) => {
// ask microservice endpoint
const { response } = await app.ask('balances', {
path: '/balances/me',
method: 'get',
params: {
userId: req.params.id,
},
});
// ask microservice action
const { response } = await app.ask('balances', {
server: {
action: 'new_deposit',
meta: {
amount: 250,
},
},
});
res.json({
id: req.params.id,
name: `${req.session.first_name} ${req.session.last_name}`,
balance: response.amount,
});
});
app.start();
port <number> Port for listen.This method creates HTTP-server and starts listen needed port. The usual use case for this method is run tests.
This method starts microservice.
FAQs
Microservice framework based on native Node.js HTTP module and AMQP protocol (express integration as feature).
The npm package micromq receives a total of 139 weekly downloads. As such, micromq popularity was classified as not popular.
We found that micromq demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.