jova.js v1.5.5
A semi-advanced Express.js framework by Bracketed Softworks! This is a package built revolving around Express.js to allow the easy usage of Express' API and adding extra things like built in middlewares, event listeners etc.
Wiki available at https://github.com/Bracketed/jova.js/wiki
- A Framework package built for Express.js that uses @bracketed/logger for logging. - It utilises a range of packages to bring you the best experience! Some of these are, ioRedis for Database-Based ratelimit buckets, Express Rate Limit for the ratelimiting middleware, CORS for CORS middleware, TCP Port Used for determining used ports and a few minor packages that can be found in the dependencies tab for small tasks in Jova.js.
Install via yarn
or npm
:
yarn add @bracketed/jova.js
npm install --save @bracketed/jova.js
Jova.js has a specific file structure it works by, this is shown below:
project
│ index.ts
│
└───events
│ │ Ready.ts
│ │ Error.ts
│ │ ...
│ │
│ └───more-events (subfolders are supported)
│ │ Mount.ts
│ │ Route.ts
│ │ ...
│
└───routes
│ │ Route.ts
│ │ Index.ts
│ │ ...
│
└───middlewares
│ Middleware1.ts
│ Middleware2.ts
│ ...
Jova.js also has two other exports, @bracketed/jova.js/utilities
and @bracketed/jova.js/types
.
@bracketed/jova.js/utilities
- Utilities for routers and middlewares currently, may contain more in future versions of Jova. Exportsrequest
andresponse
, utilities containers. All are documented using jsDoc.@bracketed/jova.js/types
- Typings for Jova.js, used in routes, middlewares, events etc.
Initiating a new Jova Server.
// ESM
import { JovaServer } from '@bracketed/jova.js';
const Jova = new JovaServer();
await Jova.listen(3000);
// CJS
const { JovaServer } = require('@bracketed/jova.js');
const Jova = new JovaServer(); // All options for JovaServer are documented in the instance as jsDocs
await Jova.listen(3000);
You can find an application example in the Jova.js repository here or the direct folder here.
The default Express API can be utilised from the default Jova instance after being initiated e.g: get(), post(), etc.
However, you can set up routes, middlewares and event listeners like this:
Events:
// ESM
// ./events/Event.ts
import { ApplicationEvent, EventController, EventListenerOptions } from '@bracketed/jova.js/types';
export class Event extends EventController {
public override setApplicationEventOptions(): EventListenerOptions {
return {
type: ApplicationEvent.ALL,
};
}
public override async run(_e: ApplicationEvent, ..._args: any[]) {
return;
}
}
// CJS
// ./events/Event.ts
const { ApplicationEvent, EventController, EventListenerOptions } = require('@bracketed.jova.js/types');
export class Event extends EventController {
public override setApplicationEventOptions(): EventListenerOptions {
return {
type: ApplicationEvent.ALL,
};
}
public override async run(_e: ApplicationEvent, ..._args: any[]) {
return;
}
}
Routes:
// ESM
// ./routes/Route.ts
import {
ApplicationRegistry,
ApplicationRequest,
ApplicationResponse,
ApplicationRoute,
Methods,
RouteController,
} from '@bracketed/jova.js/types';
export class Route extends RouteController {
public override registerApplicationRoutes(registry: ApplicationRegistry): ApplicationRoute {
return registry.registerApplicationRoutes((route) =>
route //
.setRouteName('')
.setMethod(Methods.GET)
);
}
public override async run(
request: ApplicationRequest,
response: ApplicationResponse
): Promise<ApplicationResponse | void> {
this.logger.info('Recieved request for', request.baseUrl);
return response.status(200).json({ message: 'Hello World!' });
}
}
// CJS
// ./routes/Route.ts
const {
ApplicationRegistry,
ApplicationRequest,
ApplicationResponse,
ApplicationRoute,
Methods,
RouteController,
} = require('@bracketed/jova.js/types');
export class Route extends RouteController {
public override registerApplicationRoutes(registry: ApplicationRegistry): ApplicationRoute {
return registry.registerApplicationRoutes((route) =>
route //
.setRouteName('')
.setMethod(Methods.GET)
);
}
public override async run(
request: ApplicationRequest,
response: ApplicationResponse
): Promise<ApplicationResponse | void> {
this.logger.info('Recieved request for', request.baseUrl);
return response.status(200).json({ message: 'Hello World!' });
}
}
Middlewares:
// ESM
// ./middlewares/Middleware.ts
import {
ApplicationNextFunction,
ApplicationRequest,
ApplicationResponse,
MiddlewareController,
MiddlewareOptions,
} from '@bracketed/jova.js/types';
export class Middleware extends MiddlewareController {
public override setApplicationMiddlewareOptions(): MiddlewareOptions {
return {
middlewareName: 'middleware',
runsOnAllRoutes: true,
};
}
public override async run(
_request: ApplicationRequest,
_response: ApplicationResponse,
next: ApplicationNextFunction
): Promise<ApplicationResponse | void> {
this.logger.info('Connected to middleware!');
return next();
}
}
// CJS
// ./middlewares/Middleware.ts
const {
ApplicationNextFunction,
ApplicationRequest,
ApplicationResponse,
MiddlewareController,
MiddlewareOptions,
} = require('@bracketed/jova.js/types');
export class Middleware extends MiddlewareController {
public override setApplicationMiddlewareOptions(): MiddlewareOptions {
return {
middlewareName: 'middleware',
runsOnAllRoutes: true,
};
}
public override async run(
_request: ApplicationRequest,
_response: ApplicationResponse,
next: ApplicationNextFunction
): Promise<ApplicationResponse | void> {
this.logger.info('Connected to middleware!');
return next();
}
}
Feel free to contribute to this project, join our discord and help us with future developments of Project Bracketed & Packages by Bracketed Softworks. Please also notify us of errors within our projects as we may not be aware of them at the time.
3 months ago