
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
zync-nest-data-module
Advanced tools
NestJS database module with database backup and file upload utilities
A comprehensive NestJS data module providing database utilities, backup services, and base service classes for modern web applications built with MongoDB and Mongoose.
# Clone the repository
git clone https://github.com/zynctech/zync-nest-data-module.git
cd zync-nest-data-module
# Install dependencies
pnpm install
# Build the library
pnpm run build
# Install from AsyncTech registry
npm install zync-nest-data-module --registry https://registry.asynctechs.com/
# or
pnpm add zync-nest-data-module --registry https://registry.asynctechs.com/
In your project's package.json:
{
"dependencies": {
"zync-nest-data-module": "file:../../zync-library/zync-nest-data-module"
}
}
Then run:
pnpm install
# In the library directory
npm link
# In your consuming project
npm link zync-nest-data-module
# Setup pnpm global bin directory (one-time setup)
pnpm setup
# In the library directory
pnpm link --global
# In your consuming project
pnpm link --global zync-nest-data-module
Import the required modules in your NestJS application:
import { Module } from '@nestjs/common';
import {
DatabaseModule,
BackupModule,
BaseService
} from 'zync-nest-data-module';
@Module({
imports: [
DatabaseModule,
BackupModule,
// ... other modules
],
})
export class AppModule {}
The DatabaseModule provides comprehensive MongoDB/Mongoose integration with repositories, transactions, and utilities.
The module includes a BaseSchema class that provides common fields for all documents:
import { BaseSchema } from 'zync-nest-data-module';
@Schema()
export class MyDocument extends BaseSchema {
@Prop({ required: true })
name: string;
@Prop()
description: string;
}
Create repositories by extending AbstractBaseRepository:
import { Injectable } from '@nestjs/common';
import { AbstractBaseRepository, IPageParams } from 'zync-nest-data-module';
@Injectable()
export class MyRepository extends AbstractBaseRepository<MyDocument> {
constructor(@InjectModel(MyDocument.name) model: SoftDeleteModel<MyDocument>) {
super(model);
}
protected buildQuery(query: Partial<MyDocument>): any {
return query;
}
public async mapData(data: any, isCreate: boolean): Promise<MyDocument> {
return data;
}
// Additional custom methods
async findByName(name: string): Promise<MyDocument[]> {
return this.find({ name });
}
}
Use transactions for complex operations:
import { Injectable } from '@nestjs/common';
import { TransactionManager } from 'zync-nest-data-module';
@Injectable()
export class MyService {
constructor(
private readonly transactionManager: TransactionManager,
private readonly myRepository: MyRepository
) {}
async complexOperation() {
return await this.transactionManager.runTransaction(async (session) => {
this.myRepository.session = session;
const doc1 = await this.myRepository.create({ name: 'Document 1' });
const doc2 = await this.myRepository.create({ name: 'Document 2' });
return { doc1, doc2 };
});
}
}
Use built-in pagination functionality:
async getPaginatedData(pageParams: IPageParams) {
return await this.myRepository.page({
...pageParams,
// additional query filters
});
}
The BackupService provides automated MongoDB backup functionality with cloud storage support.
Configure backup settings using environment variables:
# Database Backup Configuration
app_env=production
mongodb_backup_connection_strings=mongodb://localhost:27017/mydb
db_backup_enabled=true
db_backup_dir=./backups
db_backup_max=10
# Cloud Storage Configuration (DigitalOcean Spaces / AWS S3)
aws_bucket=my-backup-bucket
aws_s3_region=nyc3
aws_access_key_id=your-access-key
aws_secret_access_key=your-secret-key
s3_spaces_endpoint=https://nyc3.digitaloceanspaces.com
s3_spaces_dir=db-backups
import { Injectable } from '@nestjs/common';
import { BackupService } from 'zync-nest-data-module';
@Injectable()
export class MyBackupService {
constructor(private readonly backupService: BackupService) {}
async createBackup() {
await this.backupService.backup();
}
async scheduleBackups() {
// Set up automated backups (runs every 6 hours by default)
this.backupService.startBackupSchedule();
}
}
The BaseService provides a generic service class with common CRUD operations:
import { Injectable } from '@nestjs/common';
import { BaseService } from 'zync-nest-data-module';
@Injectable()
export class MyService extends BaseService<MyDocument> {
constructor(myRepository: MyRepository) {
super(myRepository);
}
// Inherits all CRUD operations:
// - create(data)
// - update(_id, data)
// - findById(_id)
// - findOne(query)
// - find(query)
// - delete(_id)
// - page(query)
// Add custom business logic
async findActiveDocuments(): Promise<MyDocument[]> {
return this.find({ deleted: false });
}
}
The module includes various utility functions:
import {
DbUtils,
ApUniqueIdGenerator,
UniqueKeyTypes
} from 'zync-nest-data-module';
// Generate unique IDs
const uniqueId = await uniqueIdGenerator.generate({
prefix: 'DOC',
key: UniqueKeyTypes.DOCUMENT,
filter: { status: 'active' }
});
// Database utilities
const isValidObjectId = DbUtils.isValidObjectId('507f1f77bcf86cd799439011');
const objectId = DbUtils.toObjectId('507f1f77bcf86cd799439011');
# Application Environment
app_env=production
NODE_ENV=production
is_docker=false
# MongoDB Configuration
mongodb_url=mongodb://localhost:27017/mydb
mongodb_backup_connection_strings=mongodb://localhost:27017/mydb
# Database Backup Configuration
db_backup_enabled=true
db_backup_dir=./backups
db_backup_max=10
# Cloud Storage Configuration (DigitalOcean Spaces / AWS S3)
aws_bucket=my-backup-bucket
aws_s3_region=nyc3
aws_access_key_id=your-access-key
aws_secret_access_key=your-secret-key
aws_s3_endpoint=https://nyc3.digitaloceanspaces.com
aws_base_key=development
s3_spaces_dir=db-backups
s3_spaces_endpoint=https://sgp1.digitaloceanspaces.com
# Build the library
pnpm run build
# Build library with clean (removes dist first)
pnpm run build:lib
# Build in watch mode
pnpm run build:watch
# Clean build artifacts
pnpm run clean
# Start the application (builds first)
pnpm run start
# Start in development mode (builds in watch mode + nodemon)
pnpm run start:dev
# Publish to AsyncTech registry
pnpm run publish:update
# Update links in consuming projects
pnpm run update-links
# Update links with version bump (minor)
pnpm run update-links:minor
# Update links with version bump (major)
pnpm run update-links:major
# Update links without building
pnpm run update-links:no-build
# Update links without version bump or build
pnpm run update-links:no-version
libs/
├── src/
│ ├── backup/ # Database backup functionality
│ │ ├── backup.config.ts
│ │ ├── backup.interface.ts
│ │ ├── backup.module.ts
│ │ ├── backup.service.ts
│ │ └── index.ts
│ ├── database/ # Database utilities and patterns
│ │ ├── database.module.ts
│ │ ├── database.repository.ts
│ │ ├── database.scheme.ts
│ │ ├── database.service.ts
│ │ ├── database.sync.ts
│ │ ├── database.transaction.ts
│ │ ├── database.uniqueId.ts
│ │ ├── database.utils.ts
│ │ └── index.ts
│ ├── service/ # Base service class
│ │ ├── service.ts
│ │ └── index.ts
│ ├── test/ # Example/test implementation
│ │ ├── test.dto.ts
│ │ ├── test.module.ts
│ │ ├── test.repository.ts
│ │ ├── test.resolver.ts
│ │ ├── test.schema.ts
│ │ └── test.service.ts
│ ├── app.controller.ts
│ ├── app.module.ts
│ ├── main.ts
│ └── index.ts # Main exports
└── tsconfig.lib.json
If pnpm link doesn't work, use the file path dependency method instead:
{
"dependencies": {
"zync-nest-data-module": "file:../../zync-library/zync-nest-data-module"
}
}
If you see peer dependency warnings (e.g., @nestjs/core version mismatch), you can:
package.json:{
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": ["@nestjs/core"]
}
}
}
Make sure to build the library first:
cd zync-nest-data-module
pnpm run build
After making changes to the library:
# In library directory
pnpm run build
# No need to reinstall - changes are automatically available in linked projects
If you encounter issues accessing the AsyncTech registry, ensure you have proper authentication:
# Login to AsyncTech registry
npm login --registry https://registry.asynctechs.com/
If you encounter any issues or have questions, please file an issue on the project repository.
FAQs
NestJS database module with database backup and file upload utilities
We found that zync-nest-data-module demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.