@nestbolt/likeable
Installation
Install @nestbolt/likeable and its required and optional peer dependencies.
Install the Package
Install @nestbolt/likeable using your preferred package manager:
npm install @nestbolt/likeableyarn add @nestbolt/likeablepnpm add @nestbolt/likeablePeer Dependencies
The following packages are required peer dependencies. In a typical NestJS project, most of these are already installed:
| Package | Required Version | Purpose |
|---|---|---|
@nestjs/common | ^10.0.0 || ^11.0.0 | NestJS core decorators and utilities |
@nestjs/core | ^10.0.0 || ^11.0.0 | NestJS application core |
@nestjs/typeorm | ^10.0.0 || ^11.0.0 | Repository injection for LikeEntity |
typeorm | ^0.3.0 | ORM used for the likes table |
reflect-metadata | ^0.1.13 || ^0.2.0 | Metadata reflection for the @Likeable() decorator |
Install any missing peer dependencies:
npm install @nestjs/common @nestjs/core @nestjs/typeorm typeorm reflect-metadataDatabase Setup
@nestbolt/likeable ships a single LikeEntity that backs the likes table. Make sure TypeORM picks it up:
import { LikeEntity } from "@nestbolt/likeable";
TypeOrmModule.forRoot({
type: "postgres",
// ... your database config
entities: [LikeEntity /* + your own entities */],
synchronize: true, // development only
});If you use TypeORM autoload (autoLoadEntities: true), LikeEntity is registered automatically once LikeableModule.forRoot() is imported -- you don't need to list it explicitly.
Optional Dependencies
Event Emitter (Like Lifecycle Events)
Required if you want to listen to like.liked and like.unliked events.
npm install @nestjs/event-emitterSupported versions: ^2.0.0 || ^3.0.0
You also need to register the EventEmitterModule in your application:
import { EventEmitterModule } from "@nestjs/event-emitter";
@Module({
imports: [
EventEmitterModule.forRoot(),
// ... other imports
],
})
export class AppModule {}If @nestjs/event-emitter is not installed or EventEmitterModule is not registered, the package works normally but no events are emitted. The event emitter is resolved lazily and treated as fully optional.
Verifying the Installation
After installing, verify everything is wired correctly by importing the module in your root AppModule:
import { Module } from "@nestjs/common";
import { TypeOrmModule } from "@nestjs/typeorm";
import { LikeableModule } from "@nestbolt/likeable";
@Module({
imports: [
TypeOrmModule.forRoot({
type: "postgres",
// ... your database config
autoLoadEntities: true,
synchronize: true, // development only
}),
LikeableModule.forRoot(),
],
})
export class AppModule {}If the application starts without errors and you see LikeableService initialized in the logs, the installation is complete. Continue to the Quick Start guide to like your first record.