All Projects → nestjs → azure-storage

nestjs / azure-storage

Licence: MIT license
Azure Storage module for Nest framework (node.js) ☁️

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to azure-storage

nestjs-ioredis
IORedis module for Nest
Stars: ✭ 21 (-70.42%)
Mutual labels:  nest, nestjs
unnue-nuxt
开媛笔记,基于nuxt ssr首屏服务器端渲染 ⚡。用于分享、记录、交流和学习,希望可以帮助到小伙伴们。同时网站在永久更新,备好鸡血,一起来战 Ooh aah!
Stars: ✭ 98 (+38.03%)
Mutual labels:  nest, nestjs
BlobHelper
BlobHelper is a common, consistent storage interface for Microsoft Azure, Amazon S3, Komodo, Kvpbase, and local filesystem written in C#.
Stars: ✭ 23 (-67.61%)
Mutual labels:  storage, azure-storage
aws-nestjs-starter
Serverless, AWS, NestJS, GraphQL and DynamoDB starter
Stars: ✭ 200 (+181.69%)
Mutual labels:  nest, nestjs
nestjs-throttler-storage-redis
Redis storage provider for the nestjs-throttler package.
Stars: ✭ 56 (-21.13%)
Mutual labels:  storage, nestjs
angular-chat
Angular v.9, Node.js, Nest.js v.6, Mongoose, Socket.io, Passport, Angular Universal SSR (in progress...)
Stars: ✭ 35 (-50.7%)
Mutual labels:  nest, nestjs
nest-xray
Distributed tracing for Nestjs with AWS X-Ray as the backend. Instrument incoming and outgoing HTTP requests
Stars: ✭ 50 (-29.58%)
Mutual labels:  nest, nestjs
ogma
A monorepo for the ogma logger and related packages
Stars: ✭ 201 (+183.1%)
Mutual labels:  nest, nestjs
nestjs-dynamoose
Dynamoose module for Nest
Stars: ✭ 84 (+18.31%)
Mutual labels:  nest, nestjs
azure-func-http
Azure Functions HTTP adapter for Nest framework (node.js) 🌥
Stars: ✭ 121 (+70.42%)
Mutual labels:  nest, nestjs
discord-nestjs
👾 NestJS package for discord.js
Stars: ✭ 173 (+143.66%)
Mutual labels:  nest, nestjs
nestjs-rest-cqrs-example
Example for Nest.js, MySQL, Redis, REST api, CQRS, DDD
Stars: ✭ 263 (+270.42%)
Mutual labels:  nest, nestjs
nestjs-session
Idiomatic Session Module for NestJS. Built on top of `express-session` 😎
Stars: ✭ 150 (+111.27%)
Mutual labels:  nest, nestjs
event-emitter
Event Emitter module for Nest framework (node.js) 🦋
Stars: ✭ 102 (+43.66%)
Mutual labels:  nest, nestjs
typegraphql-nestjs
TypeGraphQL integration with NestJS
Stars: ✭ 117 (+64.79%)
Mutual labels:  nest, nestjs
azure-serverless-deprecated
[Deprecated] Azure Serverless module for Nest framework (node.js) 🌩
Stars: ✭ 44 (-38.03%)
Mutual labels:  nest, nestjs
bundled-nest
💥 Nest 🔰 Webpack 🔰 Docker 💥 --- 🏯 Now archived for historical reference ⛩
Stars: ✭ 59 (-16.9%)
Mutual labels:  nest, nestjs
nestjs-starter
🚀 Nest framework starter
Stars: ✭ 30 (-57.75%)
Mutual labels:  nest, nestjs
nestjs-extensions
[WIP] A bunch of useful and opinionated filters, modules, pipes... to use with Nest framework. 😻
Stars: ✭ 43 (-39.44%)
Mutual labels:  nest, nestjs
nestjs-otel
OpenTelemetry (Tracing + Metrics) module for Nest framework (node.js) 🔭
Stars: ✭ 273 (+284.51%)
Mutual labels:  nest, nestjs

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads Travis Linux Coverage Discord Backers on Open Collective Sponsors on Open Collective

Description

Azure Storage module for Nest framework (node.js)

Tutorial

Learn how to get started with Azure table storage for NestJS

Before Installation

  1. Create a Storage account and resource (read more)
  2. In the Azure Portal, go to Dashboard > Storage > your-storage-account.
  3. Note down the "AccountName", "AccountKey" obtained at Access keys and "AccountSAS" from Shared access signature under Settings tab.

(Recommended) Installation and automatic configuration

Using the Nest CLI:

$ nest add @nestjs/azure-storage

Additional options

You can pass additional flags to customize the post-install schematic. For example, if your base application directory is different than src, use --rootDir flag:

$ nest add @nestjs/azure-storage --rootDir app

When requested, provide the storageAccountName and storageAccountSAS (see below).

Other available flags:

  • rootDir - Application root directory, default: src
  • rootModuleFileName - the name of the root module file, default: app.module
  • rootModuleClassName - the name of the root module class, default: AppModule
  • mainFileName - Application main file, default: main
  • skipInstall - skip installing dependencies, default: false
  • storageAccountName (required) - The Azure Storage account name (see: http://bit.ly/azure-storage-account)
  • storageAccountSAS (required) - The Azure Storage SAS Key (see: http://bit.ly/azure-storage-sas-key).

(Option 2) Manual configuration

  1. Install the package using NPM:
$ npm i -S @nestjs/azure-storage
  1. Create or update your existing .env file with the following content:
# See: http://bit.ly/azure-storage-sas-key
AZURE_STORAGE_SAS_KEY=
# See: http://bit.ly/azure-storage-account
AZURE_STORAGE_ACCOUNT=

The SAS has the following format: ?sv=2018-03-28&ss=bfqt&srt=sco&sp=rwdlacup&se=2019-12-31T22:54:03Z&st=2019-07-11T13:54:03Z&spr=https,http&sig=WmAl%236251oj11biPK2xcpLs254152H9s0%3D

  1. IMPORTANT: Make sure to add your .env file to your .gitignore! The .env file MUST NOT be versionned on Git.

  2. Make sure to include the following call to your main file:

if (process.env.NODE_ENV !== 'production') require('dotenv').config();

This line must be added before any other imports!

  1. Import the AzureStorageModule with the following configuration:
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AzureStorageModule } from '@nestjs/azure-storage';

@Module({
  controllers: [AppController],
  providers: [AppService],
  imports: [
    AzureStorageModule.withConfig({
      sasKey: process.env['AZURE_STORAGE_SAS_KEY'],
      accountName: process.env['AZURE_STORAGE_ACCOUNT'],
      containerName: 'nest-demo-container',
    }),
  ],
})
export class AppModule {}

If you want to use asynchronous configuration options using factory or class,

const storageConfigFactory = async () => {
  sasKey: process.env['AZURE_STORAGE_SAS_KEY'],
  accountName: process.env['AZURE_STORAGE_ACCOUNT'],
  containerName: 'nest-demo-container',
};

@Module({
  controllers: [AppController],
  providers: [AppService],
  imports: [
    AzureStorageModule.withConfigAsync({
      useFactory: storageConfigFactory,
    }),
  ],
})
export class AppModule {}

You may provide a default containerName name for the whole module, this will apply to all controllers withing this module. You can also provide (override) the containerName in the controller, for each route.

Story examples

Store a file using the default container name

import {
  Controller,
  Logger,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import {
  AzureStorageFileInterceptor,
  UploadedFileMetadata,
} from '@nestjs/azure-storage';

@Controller()
export class AppController {
  
  @Post('azure/upload')
  @UseInterceptors(
    AzureStorageFileInterceptor('file'),
  )
  UploadedFilesUsingInterceptor(
    @UploadedFile()
    file: UploadedFileMetadata,
  ) {
    Logger.log(`Storage URL: ${file.storageUrl}`, 'AppController');
  }
}

Store a file using a specific container name

import {
  Controller,
  Logger,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import {
  AzureStorageFileInterceptor,
  UploadedFileMetadata,
} from '@nestjs/azure-storage';

@Controller()
export class AppController {
  
  @Post('azure/upload')
  @UseInterceptors(
    AzureStorageFileInterceptor('file', null, {
      containerName: 'nest-demo-container-interceptor',
    }),
  )
  UploadedFilesUsingInterceptor(
    @UploadedFile()
    file: UploadedFileMetadata,
  ) {
    Logger.log(`Storage URL: ${file.storageUrl}`, 'AppController');
  }
}

Store a file using a custom file name

import {
  Controller,
  Logger,
  Post,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import {
  AzureStorageFileInterceptor,
  AzureStorageService,
  UploadedFileMetadata,
} from '@nestjs/azure-storage';

@Controller()
export class AppController {
  constructor(private readonly azureStorage: AzureStorageService) {}
  
  @Post('azure/upload')
  @UseInterceptors(FileInterceptor('file'))
  async UploadedFilesUsingService(
    @UploadedFile()
    file: UploadedFileMetadata,
  ) {
    file = {
      ...file,
      originalname: 'foo-bar.txt',
    };
    const storageUrl = await this.azureStorage.upload(file);
    Logger.log(`Storage URL: ${storageUrl}`, 'AppController');
  }
}

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].