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.
See Changelog for more information.
- Martin Andreev [email protected]
Licensed under the MIT License - see the LICENSE file for details.
To install the module simple run
npm install minio-nestjs-client
or
yarn add minio-nestjs-client
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';
}
}
- Clone the repo
- Run yarn install
cd minio-nestjs-client
yarn install
yarn test