Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

A simple NestJS module that wraps the Minio Node.js library in a more familiar way
https://github.com/martinandreev/minio-nestjs-client

minio nest nestjs nodejs typescript

Last synced: 10 days ago
JSON representation

A simple NestJS module that wraps the Minio Node.js library in a more familiar way

Awesome Lists containing this project

README

        



Nest Logo

NestJS Minio Client



Built with NestJS

![main](https://github.com/MartinAndreev/minio-nestjs-client/actions/workflows/test.yml/badge.svg?branch=main)

This is a really simple NestJS module, that lets you initialize the [minio client](https://docs.min.io/docs/javascript-client-api-reference.html)
in a NestJS friendly way and provides a handy way to inject the client.

## Change Log

See [Changelog](CHANGELOG.md) for more information.

## Authors

- **Martin Andreev **

## License

Licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Installation

To install the module simple run

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

or

```bash
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:

```typescript
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`.

```typescript
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`.

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

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

And to access the client just use the Injection token

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

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

public async doSomethingWithABucket(): Promise {
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

```bash
cd minio-nestjs-client
yarn install
```

## Running tests

```bash
yarn test
```