npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nest-aws-s3

v0.0.9

Published

A Comprehensive, Easy-to-Use NestJS Module for Amazon S3 Integration

Downloads

27

Readme

nest-aws-s3

This is a simple, clean, and easy-to-use NestJS module for Amazon S3 integration, leveraging the latest AWS SDK v3. It's designed for quick integration and minimal setup, making your development process smoother.

Features

  • Easy integration with AWS S3 for NestJS applications.
  • Clean and optimized codebase.
  • Wide range of S3 functionalities.

Installation

npm install nest-aws-s3

Configuration

In your NestJS module:

import { S3Module } from 'nest-aws-s3';

@Module({
  imports: [
    S3Module.forRoot({
      defaultServiceOptions: {
        region: 'us-east-1',
        credentials: {
          accessKeyId: 'your-access-key',
          secretAccessKey: 'your-secret-key',
        },
      },
    }),
    // ... other imports
  ],
})
export class AppModule {}

Usage

Upload a File

@Injectable()
export class YourService {
  constructor(private readonly s3Service: S3Service) {}

  async uploadFile(file: Buffer, bucket: string, key: string) {
    return this.s3Service.uploadFile(bucket, key, file);
  }
}

Retrieve a File

export class YourService {
    constructor(private readonly s3Service: S3Service) {
    }

    async getFile(bucket: string, key: string) {
        return this.s3Service.getFile(bucket, key);
    }
}

Delete a File

export class YourService {
    constructor(private readonly s3Service: S3Service) {
    }

    async deleteFile(bucket: string, key: string) {
        return this.s3Service.deleteFile(bucket, key);
    }
}

Supported Methods

The nest-aws-s3 package includes a variety of methods for interacting with AWS S3, including:

  • uploadFile(bucket: string, key: string, body: Buffer): Upload a file to a specified bucket.
  • getFile(bucket: string, key: string): Retrieve a file from a specified bucket.
  • deleteFile(bucket: string, key: string): Delete a file from a specified bucket.
  • deleteFiles(bucket: string, keys: string[]): Delete multiple files from a specified bucket.
  • listFiles(bucket: string): List all files in a specified bucket.
  • copyFile(sourceBucket: string, sourceKey: string, destBucket: string, destKey: string): Copy a file within or across buckets.
  • createBucket(bucket: string): Create a new S3 bucket.
  • deleteBucket(bucket: string): Delete an S3 bucket.
  • getSignedUrl(bucket: string, key: string, expires: number): Generate a signed URL for a file.
  • moveFile(sourceBucket: string, sourceKey: string, destBucket: string, destKey: string): Move a file within or across buckets.

These methods provide comprehensive coverage of common S3 operations, simplifying the process of integrating AWS S3 into your NestJS applications.

Helper Classes and Their Methods

Our nest-aws-s3 module enhances S3 operations with several helper classes:

UploadFileChain

  • withUrl(): Generates a URL for the uploaded file.
  • withPublicAccess(allowPublicAccess: boolean): Sets the file's public access.

GetFileChain

  • withMetaData(): Retrieves metadata of the file.
  • withDownloadLink(): Generates a download link for the file.

ListFilesChain

  • listFilesWithFilter(prefix?: string, suffix?: string): Filters files with specific prefix and/or suffix.
  • getBucketSize(): Calculates the total size of all files in the bucket.

Contributing

Feel free to contribute, report issues, and request features!

License

This project is licensed under the ISC License.