@patterujs/cli

1.0.1 • Public • Published

Patteru JS

A Node.js CLI Tool for small load balancer

npm NPM GitHub last commit

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

Dependents (0)

Package Sidebar

Install

npm i @patterujs/cli

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

23.7 kB

Total Files

44

Last publish

Collaborators

  • patterujs