NestJS Azure Data Lake Storage
Overview
Azure Data Lake Storage(ADLS) module for NestJS framework.
Before installation
- Create Azure Data Lake Storage resource (read more).
- Get credentials from Azure Data Lake Storage using Azure Portal.
Installation
npm i --save @azure/storage-file-datalake nestjs-adls
Usage
- Import AdlsModule to your AppModule:
import {Module} from '@nestjs/common';
import {StorageSharedKeyCredential} from '@azure/storage-file-datalake';
import {AdlsModule} from 'nestjs-adls';
@Module({
imports: [
AdlsModule.forRoot({
url: 'ADLS_URL',
fileSystemName: 'ADLS_FILE_SYSTEM_NAME',
credential: new StorageSharedKeyCredential(
'ADLS_ACCOUNT_NAME',
'ADLS_ACCOUNT_KEY'
)
})
],
providers: [AppService]
})
export class AppModule {
}
Or async:
import {Module} from '@nestjs/common';
import {StorageSharedKeyCredential} from '@azure/storage-file-datalake';
import {AdlsModule} from 'nestjs-adls';
@Module({
imports: [
AdlsModule.forRootAsync({
useFactory: () => ({
url: 'ADLS_URL',
fileSystemName: 'ADLS_FILE_SYSTEM_NAME',
credential: new StorageSharedKeyCredential(
'ADLS_ACCOUNT_NAME',
'ADLS_ACCOUNT_KEY'
)
})
})
],
providers: [AppService]
})
export class AppModule {
}
- Use
@InjectFileSystemClient()
decorator to injectDataLakeFileSystemClient
. (will be used fileSystemName from AdlsModule options).
import {Injectable} from '@nestjs/common';
import {DataLakeFileSystemClient} from '@azure/storage-file-datalake';
import {InjectFileSystemClient} from 'nestjs-adls';
@Injectable()
export class AppService {
constructor(@InjectFileSystemClient() private readonly adlsClient: DataLakeFileSystemClient) {
}
}
Or use @InjectDataLakeClient()
decorator to inject DataLakeServiceClient
.
import {Injectable} from '@nestjs/common';
import {DataLakeServiceClient} from '@azure/storage-file-datalake';
import {InjectDataLakeClient} from 'nestjs-adls';
@Injectable()
export class AppService {
constructor(@InjectDataLakeClient() private readonly adlsClient: DataLakeServiceClient) {
}
}