Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/djedlajn/nestjs-minio-client

Minio client sdk for NestJS
https://github.com/djedlajn/nestjs-minio-client

minio minio-client-sdk nestjs typescript

Last synced: about 2 months ago
JSON representation

Minio client sdk for NestJS

Awesome Lists containing this project

README

        




Nestjs Minio Client

Minio client for NestJs.

## Features

- Configure and connect to Minio instance

## Prerequisites

- NestJS version 9 or later.

### Installation

**Yarn**

```bash
yarn add nestjs-minio-client
```

**NPM**

```bash
npm install nestjs-minio-client --save
```

### Getting Started

To use Minio client we need to register module for example in `app.module.ts`

```ts
import { Module } from '@nestjs/common';
import { MinioModule } from 'nestjs-minio-client';

@Module({
imports: [
MinioModule.register({
endPoint: '127.0.0.1',
port: 9000,
useSSL: false,
accessKey: 'minio_access_key',
secretKey: 'minio_secret_key'
})
})

export class AppModule {}
```

If you are using the `@nestjs/config` package from nest, you can use the `ConfigModule` using the `registerAsync()` function to inject your environment variables like this in your custom module:

```ts
import { Module } from '@nestjs/common';
import { MinioModule } from 'nestjs-minio-client';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
imports: [
MinioModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => {
return {
endPoint: config.get('MINIO_ENDPOINT'),
port: parseInt(config.get('MINIO_PORT')),
useSSL: false,
accessKey: config.get('MINIO_ACCESS_KEY'),
secretKey: config.get('MINIO_SECRET_KEY'),
};
},
}),
],
providers: [MinioClientService],
exports: [MinioClientService],
})
export class MinioClientModule {}
```

After the registration connection to minio instance should be completed and ready for usage.

Example usage in service.

```ts
import { Injectable } from '@nestjs/common';
import { MinioService } from 'nestjs-minio-client';

@Injectable()
export class ContentService {
constructor(private readonly minioService: MinioService) {}

async listAllBuckets() {
return this.minioService.client.listBuckets();
}
}
```

For full Client API see Minio Javascript SDK reference [here](https://docs.min.io/docs/javascript-client-api-reference.html)

---