1.0.7 • Published 2 years ago

minio-nestjs-client v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

main

This is a really simple NestJS module, that lets you initialize the minio client in a NestJS friendly way and provides a handy way to inject the client.

Change Log

See Changelog for more information.

Authors

License

Licensed under the MIT License - see the LICENSE file for details.

Installation

To install the module simple run

npm install minio-nestjs-client

or

yarn add minio-nestjs-client

Usage

As this is a simple wrapper usage is pretty straigth forward. Just import the MinioModule and initialize it. There are two ways to do this, a simple config and async config.

To use the simple config just:

import { MinioModule } from 'minio-nestjs-client';

MinioModule.forRoot({
  endPoint: 'play.min.io',
  port: 9000,
  useSSL: true,
  accessKey: 'Q3AM3UQ867SPQQA43P2F',
  secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
});

However, there are times, where configuration if loaded from a service or depends on other providers. This can be achived using the MinioModule.forRootAsync.

import { MinioModule } from 'minio-nestjs-client';

MinioModule.forRootAsync({
  useFactory: () =>
    new Promise((resolve) => {
      resolve({
        endPoint: 'play.min.io',
        port: 9000,
        useSSL: true,
        accessKey: 'Q3AM3UQ867SPQQA43P2F',
        secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
      });
    }),
});

Here is also an example, that uses the @nestjs/config.

import { MinioModule, MinioConfig } from 'minio-nestjs-client';

MinioModule.forRootAsync({
  useFactory: (config) => {
    return config.get<MinioConfig>('config-key');
  },
  inject: [ConfigService],
  import: [ConfigModule],
});

And to access the client just use the Injection token

import { MINIO_CLIENT, MinioClient } from 'minio-nestjs-client';

@Injectable()
export class MyService {
  public constructor(private readonly client: MinioClient) {}

  public async doSomethingWithABucket(): Promise<string> {
    const bucketExists = await this.client.bucketExists('test');

    return bucketExists ? 'We have a bucket' : 'We dont have a bucket';
  }
}

Development

  1. Clone the repo
  2. Run yarn install
cd minio-nestjs-client
yarn install

Running tests

yarn test
1.0.7

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago