
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@vcita/infra-nestjs
Advanced tools
Nest TypeScript repository containing infrastructure for new vcita services
To build and run this app locally you will need a few things:
git clone git@github.com:vcita/nestjs-service-template.git
For better code editor auto-complete:
cd <project_name>
npm install
You must define a module with the base requirements to support all features that described below Features.
Example: src/notes/notes.module.ts
.
Then import your module in the src/app.module.ts
.
You can run the app with its dependencies (RedisDB, MySQL) using docker compose:
$ docker-compose up
By default, the app running in watch mode, You can modify it in the Dockerfile.
Optional Run commands:
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
The controllers are based on decorators that defined the controller's functionality and also the swagger (As described below).
The controller (src/notes/controllers/notes.controller.ts
) demonstrates how to implement CRUD actions with decorators that also served the swagger.
For more details visit here
Database is configured by default.
TypeORM chosen as ORM library, it supports multiple types of DBs (including NoSQL DBs).
The template works with TypeORM based on repository design pattern.
src/notes/note.entity.ts
(Make sure that you are using the correct decorators).
src/infra/repositories/base.entity.ts
for getting all base data that we need.src/notes/notes.repository.ts
.
src/infra/repositories/base.repository.ts
npm run typeorm -- migration:generate -n <YOUR_MIGRATION_NAME>
- auto-generating migration from your entity definition, read morenpm run typeorm -- migration:run
- read moremain port 48388 worker port <service_port_worker> swagger name <swagger_name>
Open API configured by default, swagger UI served at route /swagger-ui
.
In the bootstrap function (In main.ts) you can edit the base data of the swagger document.
Swaggers are building using decorators.
For more details visit here.
The template using interceptor to handle application timeouts through app global interceptor.
By default, the timeout for any request configured to 100 milliseconds and return RequestTimeoutException if needed.
The timeout interceptor implementation - timeout.interceptor.ts .
The template contains a default logger service: src/infra/services/infra-logger.service.ts
.
Infra logger service parse all data that we need for our infrastructure service (Kibana for example).
The template also including a middleware logger that logged all HTTP requests: src/infra/middlewares/logger.middleware.ts
.
For more details visit here.
The chosen library for metrics is NestJS Prometheus.
By default, this will register a /metrics
endpoint that will return the default metrics.
To inject costume metrics see Injecting individual metrics section
NestJS supplies a library which gives the ability to expose health checks and readiness.
Basic health check already implemented as part if the template:
For more details visit here.
Declare a cron job with the @Cron() decorator preceding the method definition containing the code to be executed.
For example:
src/notes/notes.service.ts#triggerNoteNotifications
src/app.service.ts#handleAppCronInterval
For more details visit here
Nest provides the @nestjs/bull package as an abstraction/wrapper on top of Bull, a popular, well supported, high performance Node.js based Queue system implementation.
The package makes it easy to integrate Bull Queues in a Nest-friendly way to your application.
Queue registration:
Set your queue's name in the as environment variable in the .env
file:
REDIS_QUEUES=<queue_name>,<queue_name>
For example: REDIS_QUEUES=notes,note_secondary_queue
or REDIS_QUEUES=notes
.
Register your queues in your module (See example in src/notes/notes.module.ts
):
const queues: BullModuleOptions[] = process.env.REDIS_QUEUES.split(',').map(
function (queue) {
return { name: queue };
},
);
BullModule.registerQueue({
name: 'notes',
})
Injection:
(See example in src/notes/services/notes.service.ts
)
@InjectQueue('notes') private readonly queue: Queue
Define queue metrics:
In the constructor of the service that injected the queue set (must be imported from infra library):
applyBullMetrics(queue)
Producing (See example in src/notes/notes.service.ts
):
await this.newNoteQueue.add('new_note', note);
Consuming (See example in src/notes/notes.processor.ts
):
@Process('new_note')
async notifier(job: Job<Note>) {
const note: Note = job.data;
const msg = `Processing job ${job.id} of type ${job.name} with data ${JSON.stringify(note)}`;
this.logger.infraLog(msg);
}
You can produce messages to the queue with different name (As we did with the 'new_note') and to consume it in different process @Process('new_note')
.
For more information visit here.
TBD
TBD
$ npm run test
or from outside the container
$ docker exec -it <CONTAINER_NAME> npm run test
$ npm run test:e2e
or from outside the container
$ docker exec -it <CONTAINER_NAME> npm run test:e2e
$ npm run test:cov
or from outside the container
$ docker exec -it <CONTAINER_NAME> npm run test:cov
infranestjs
48388
<context_name>
<database_type>
<database_host>
<database_port>
<database_name>
<database_user>
<database_password>
<redis_host>
<redis_port>
<redis_port>
<oauth_redirect_uri>
<oauth_client_secret>
<oauth_client_id>
<oauth_server>
<api_gw_server>
FAQs
Nest TypeScript repository containing infrastructure for new vcita services
The npm package @vcita/infra-nestjs receives a total of 24 weekly downloads. As such, @vcita/infra-nestjs popularity was classified as not popular.
We found that @vcita/infra-nestjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.