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

@icapps/tree-house-storage

v2.0.0

Published

Tree House Storage

Downloads

23

Readme

Treehouse storage

NodeJS storage utility module written in Typescript

npm version Dependencies Build Status Coverage Status Greenkeeper badge

Installation

Install via npm

npm install @icapps/tree-house-storage

or via yarn

yarn add @icapps/tree-house-storage

Usage

Middleware functions

multipartUpload(options)

Express middleware function to upload a local file using multer.

import { middleware } from '@icapps/tree-house-storage'

const options = {
  destination: 'uploads',
  fileSize: 12000,
  allowedFileTypes: ['image/png', 'image/jpg'],

  // Optional Joi schema validation for other body data
  validator: {
    schema: joiSchema,
    options: joiOptions,
  };
};

app.post('/upload', middleware.multipartUpload(options), ...);

More information on Multer

Local filesystem

Local file functions enabling the use of Promises for fs methods.

More information on fs

createIfNotExists(path)

Creates a folder if it doesn't exist already. (Asynchronous)

import { local } from '@icapps/tree-house-storage'
await local.createIfNotExists('/localFolder');

createFile(path, name, content)

Creates a new local file. This will also create a folder when it does not exist already. (Asynchronous)

import { local } from '@icapps/tree-house-storage'
await local.createFile('/localFolder', 'myFile.txt', 'My personal content');

readFile(path)

Read an existing local file via filepath. (Asynchronous)

import { local } from '@icapps/tree-house-storage'
await local.readFile('/localFolder', 'myFile.txt', 'My personal content');

deleteFile(path)

Delete an existing local file via filepath (Asynchronous)

import { local } from '@icapps/tree-house-storage'
await local.deleteFile('/localFolder/myFile.txt');

Amazon

Amazon S3 libs

More information on AWS S3

createClient(clientOptions)

Create an S3 client

import { amazon } from '@icapps/tree-house-storage'

const options = {
  region: 'eu-west-1',
  accessKeyId: 'myAccesKey',
  secretAccessKey: 'mySecret',
};
const client = amazon.createClient(options);

uploadFile(client, options)

Upload a file to S3

import { amazon } from '@icapps/tree-house-storage'

const options = {
  path: 'localPath/localFile.png',
  content: 'fileContent ...',
  name: uuid.v4(),
  contentType: 'image/png',
  bucket: 's3bucketName',
  key: 's3KeyName',
  encryption: 'AE-256', // Optional encryption (this will enable server encryption on S3)
};
const { location, bucket, key } = await amazon.uploadFile(client, options);

getFile(client, bucket, key)

Retrieve a file from S3

import { amazon } from '@icapps/tree-house-storage'

const { body } = await amazon.getFile(client, bucket, key);

removeFile(client, bucket, key)

Remove a file from S3

import { amazon } from '@icapps/tree-house-storage'

await amazon.removeFile(client, bucket, key);

getPresignedUrl(client, options)

Gets a pre-signed url for an S3 resource

import { amazon } from '@icapps/tree-house-storage'

const options = {
  bucket: 's3bucketName',
  key: 's3KeyName',
  expires: 1600, // Optional expiration time
};
const { location, bucket, key } = await amazon.getPresignedUrl(client, options);

getUploadPresignedUrl(client, options)

Gets a pre-signed upload url for an S3 resource

import { amazon } from '@icapps/tree-house-storage'

const options = {
  bucket: 's3bucketName',
  key: 's3KeyName',
  expires: 1600, // Optional expiration time
  contentType: 'image/png' // Optional but best practice to include this
};

const url = await amazon.getUploadPresignedUrl(client, options);

Tests

All tests are written using Jest. Check out the documentation here for more information.

You can run npm run test to run all tests

You can run npm run test:coverage to run all tests with coverage report

Bugs

When you find issues, please report them:

Be sure to include all of the output from the npm command that didn't work as expected. The npm-debug.log file is also helpful to provide.

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the ISC License - see the LICENSE.md file for details