Enterprise-grade TypeScript application with NestJS and NexaDB.
# Create NestJS app
npx @nestjs/cli new nexadb-app
cd nexadb-app
# Install NexaDB client
npm install nexaclientimport { Module, Global } from '@nestjs/common';
import { DatabaseService } from './database.service';
@Global()
@Module({
providers: [DatabaseService],
exports: [DatabaseService],
})
export class DatabaseModule {}import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import NexaClient from 'nexaclient';
@Injectable()
export class DatabaseService implements OnModuleInit, OnModuleDestroy {
private client: NexaClient;
async onModuleInit() {
this.client = new NexaClient({
host: process.env.NEXA_HOST || 'localhost',
port: parseInt(process.env.NEXA_PORT) || 6970,
username: 'root',
password: 'nexadb123'
});
await this.client.connect();
console.log('✓ Connected to NexaDB');
}
async onModuleDestroy() {
await this.client.disconnect();
}
getClient(): NexaClient {
return this.client;
}
}import { Injectable } from '@nestjs/common';
import { DatabaseService } from '../database/database.service';
@Injectable()
export class UsersService {
constructor(private readonly dbService: DatabaseService) {}
async create(userData: any) {
const db = this.dbService.getClient();
return db.create('users', userData);
}
async findOne(id: string) {
const db = this.dbService.getClient();
return db.get('users', id);
}
async findAll(limit = 10) {
const db = this.dbService.getClient();
return db.query('users', {}, { limit });
}
async update(id: string, userData: any) {
const db = this.dbService.getClient();
return db.update('users', id, userData);
}
async remove(id: string) {
const db = this.dbService.getClient();
return db.delete('users', id);
}
}NestJS provides dependency injection, decorators, and modular architecture perfect for large-scale applications.