0.0.7 • Published 2 years ago

nestjs-file-system v0.0.7

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

Installation

Installation

npm install nestjs-file-system

About nestjs-file-system

Pre-release, in development

I'm coding this library for my needs, but I'm open to feature submissions

Inject module in your nestJs project

NestJs-File-System is build using the NestJs Dynamic modules and Factory providers approach, to configure it import the NfsModule module and the forRootFtpAsync service.

For example, your AppModule should look like this :

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config'
import { NfsModule } from 'nestjs-file-system';

@Module({
  imports: [
    ConfigModule,
    NfsModule.forRootFtpAsync(),
  ],
  providers: [],
  controllers: [],
})
export class AppModule {}

Then just inject the service just like any local service

For Example:

import { Injectable, ServiceUnavailableException, Logger } from '@nestjs/common';
import { NfsModule } from 'nestjs-file-system';

@Injectable()
export class AppService {
    private logger = new Logger('AppService', { timestamp: true });
    constructor(private readonly _nfsService: NfsModule){}

  public listFile(path: string): Dirent[] {
    try {
      return this._nfsService.listFile(path)
    } catch (e) {
      this.logger.error(JSON.stringify(e));
      throw new ServiceUnavailableException(e);
    }
  }
}

License

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