@y5systems/lightjs
v0.1.1
Published
A lightweight Node.js framework designed to simplify the creation of efficient applications.
Readme
LightJS
A lightweight Node.js framework designed to simplify the creation of streamlined and efficient applications.
Features
- Minimalistic and Intuitive: Get started quickly.
- Focused on Simplicity: Ideal for small to medium-sized projects that prioritize efficiency.
- Built for Microservices: Easily create independent services for scalable applications.
Installation
npm install @y5systems/lightjsGetting Started
This framework uses RabbitMQ for communication between services. Make sure to have it up and running before you run your application.
Create a Project:
mkdir my-app && cd my-app
npm init -yNote: This documentation uses TypeScript, make sure to install it and to add a tsconfig.json file.
Install the Framework:
npm install -s @y5systems/lightjsCreate your main file (e.g. index.ts):
import startApplication from '@y5systems/lightjs';
const appRootPath = dirname(fileURLToPath(import.meta.url));
startApplication(appRootPath).then();Create a service to produce messages (e.g. producer.ts):
mkdir -p services/producerimport {MessageBroker, Service} from '@y5systems/lightjs';
export default class Producer extends Service {
constructor(messageBroker: MessageBroker, serviceConfiguration: Record<string, unknown>) {
super(messageBroker, serviceConfiguration);
}
async run(): Promise<void> {
const interval = setInterval(() => {
this.sendMessage('consumer', 'messageLogger', {message: 'producing...'});
}, 1000);
}
}Create a service to consume messages (e.g. consumer.ts):
mkdir -p services/consumerimport {MessageBroker, Service} from '@y5systems/lightjs';
export default class Consumer extends Service {
constructor(messageBroker: MessageBroker, serviceConfiguration: Record<string, unknown>) {
super(messageBroker, serviceConfiguration);
}
async run(): Promise<void> {
this.messageBroker.messageConsumers.set('messageLogger', new MessageLogger(this.messageBroker.eventEmitter));
}
}import {EventEmitter} from 'node:events';
import {MessageConsumer} from '@y5systems/lightjs';
class MessageLogger extends MessageConsumer {
constructor(eventEmitter: EventEmitter) {
super(eventEmitter);
}
async consume(data: Record<string, unknown>): Promise<void> {
console.log(data.message);
}
}Create the configuration file (e.g. development.json):
mkdir config[
{
"service": "producer",
"name": "producer-01",
"serviceConfiguration": {}
},
{
"service": "consumer",
"name": "consumer-01",
"serviceConfiguration": {}
}
]Setup your environment:
NODE_ENV=development
SERVICES=
RABBITMQ_HOSTNAME=127.0.0.1
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=rabbitmq-username
RABBITMQ_PASSWORD=rabbitmq-password
RABBITMQ_VHOST=rabbitmq-vhostNote: You can choose what services to run using the SERVICES variable (An empty string will run all services on the configuration file).
Run the application:
node --env-file=.env index.jsLicense
This project is licensed under the MIT License - see the LICENSE file for details.
