@patterujs/cli
v1.0.1
Published
Patteru - Small load balancer for developers
Downloads
3
Maintainers
Readme
Patteru JS
A Node.js CLI Tool for small load balancer
Description
The Patteru CLI is a command line interface tool for helps you to test run your project in load balancer.
Installing
Installing for global use
npm i -g @patterujs/cli
Installing in current project
npm i --save-dev @patterujs/cli
After the installation is complete, add a script to package.json in your project.
{
"script": {
"balancer": "patteru start filename.js"
}
}
Usage
To run your project using PatteruJS, you have to add process.env.PORT
into your project as in the example below.
Example of use in Express
// index.js
const express = require('express');
const app = express();
const port = process.env.PORT;
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
To run it
patteru start index.js
Example of use in Fastify
// index.js
const fastify = require('fastify')({
logger: true,
});
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' });
});
fastify.listen(process.env.PORT, function (err, address) {
if (err) {
fastify.log.error(err);
process.exit(1);
}
fastify.log.info(`server listening on ${address}`);
});
To run it
patteru start index.js
Example of use in Nestjs
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(process.env.PORT);
}
bootstrap();
Before running it, make the project first.
npm run build
To run it
patteru start dist/main.js
License
PatteruJS is MIT Licensed