@svtslv/nestjs-minio
v1.0.1
Published
Nest - modern, fast, powerful node.js web framework (@minio)
Downloads
218
Readme
NestJS Minio
Table of Contents
Description
Integrates Minio with Nest
Installation
npm install @svtslv/minio minio
npm install -D @types/minio
You can also use the interactive CLI
npx nestjs-modules
Examples
docker run \
-p 9000:9000 \
-e MINIO_ACCESS_KEY=minio \
-e MINIO_SECRET_KEY=password \
minio/minio server /data
MinioModule.forRoot(options, connection?)
import { Module } from '@nestjs/common';
import { MinioModule } from '@svtslv/nestjs-minio';
import { AppController } from './app.controller';
@Module({
imports: [
MinioModule.forRoot({
config: {
// url: 'http://minio:password@localhost:9000',
accessKey: 'minio',
secretKey: 'password',
endPoint: 'localhost',
port: 9000,
useSSL: false,
},
}),
],
controllers: [AppController],
})
export class AppModule {}
MinioModule.forRootAsync(options, connection?)
import { Module } from '@nestjs/common';
import { MinioModule } from '@svtslv/nestjs-minio';
import { AppController } from './app.controller';
@Module({
imports: [
MinioModule.forRootAsync({
useFactory: () => ({
config: {
// url: 'http://minio:password@localhost:9000',
accessKey: 'minio',
secretKey: 'password',
endPoint: 'localhost',
port: 9000,
useSSL: false,
},
}),
}),
],
controllers: [AppController],
})
export class AppModule {}
InjectMinioClient(connection?)
import { Controller, Get, } from '@nestjs/common';
import { InjectMinioClient, MinioClient } from '@svtslv/nestjs-minio';
@Controller()
export class AppController {
constructor(
@InjectMinioClient() private readonly minioClient: MinioClient,
) {}
@Get()
async getHello() {
if(!await this.minioClient.bucketExists('bucket2')) {
await this.minioClient.makeBucket('bucket2', '');
}
return await this.minioClient.listBuckets()
}
}
License
MIT