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

simple-do-spaces

v0.9.0

Published

Simple Client to handle Digital Ocean Spaces files.

Downloads

370

Readme

Simple Digital Ocean Spaces Client

Build Status dependencies Status devDependencies Status License: MIT

NPM

Usage

Credentials setup

You can set the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_KEY as default credentials for the S3 SDK which is also used by Digital Ocean Spaces API.

Create client for Digital Ocean Spaces API

import SpacesClient from 'simples-do-spaces';

const client = new SpacesClient(
  'sfo2.digitaloceanspaces.com', // Required, Digital Ocean Spaces Endpoint
  'bucketName', // Required. Bucket name
  'accessKeyId', // Optional. Access key, can be provided via env var AWS_ACCESS_KEY_ID
  'secretAccessKey' // Optional. Access key secret, can be env var AWS_SECRET_ACCESS_KEY
  'digitalOceanAPIToken' // Optional. Digital Ocean API Token, used to purge the cdn cache
  'cdnEndpointId' // Optional. CDN's Endpoint Id, used to purge the cdn cache,
                     // if not provided will be auto-extracted from bucketName.
);

All methods returns a Promise which resolves to the values described below.

Upload file

client.uploadFile(uploadFilePath, destinationPath, permission);
  • uploadFilePath : File path in file system
  • destinationPath : Path to save in DO Spaces
  • permission : Permission of the file, default is private, can also be public-read.
  • options : Options object to be sent to S3 SDK
    • exponentialBackoff : Use exponential backoff if the upload failed
    • purgeCache : Purge the cache from CDN related to this new file

Return file URL in DO Spaces CDN

List files

client.listPathFiles(path, options = {});
  • path : Path in DO Spaces to list
  • options : Options object
    • sortByDate : Sort files by LastModified date, can be 'ASC' (default) or 'DESC'
    • pathOnly : If true it will not return the complete URL just the path in DO Spaces

Return array of objects with the 'url' and 'lastModified' properties

[ { url: 'file url', lastModified: Date }, ... ]

Delete one file

client.deleteFile(path);
  • path : Relative path to one file in DO spaces to delete it

Delete multiple files

client.deletePaths(paths);
  • paths : Array of relative paths in DO spaces to delete

Copy file within DO Spaces

client.copyFile(sourcePath, destinationPath);

Download file

client.downloadFile(filePathToRead, filePathToSave, createDirIfNotExists);
  • filePathToRead : Path in DO Spaces
  • filePathToSave : Path to save in file system
  • createDirIfNotExists : Boolean to create the folder if the it doesn't exists. Default is true

Get Pre-signed URL for private files

client.getPresignedURL(path, expires);
  • path : Path for the file to get the pre-signed URL
  • expires : Time to expire the pre-signed URL (in seconds) (defaults to 900 seconds / 15 minutes);

License

MIT © Bruno Orlandi