🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

tree-house-storage

Package Overview
Dependencies
Maintainers
5
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-house-storage

Tree House Storage

latest
npmnpm
Version
1.0.2
Version published
Maintainers
5
Created
Source

Treehouse storage

NodeJS storage utility module written in Typescript

npm version Dependencies Build Status Coverage Status Greenkeeper badge

Installation

Install via npm

npm install tree-house-storage

or via yarn

yarn add tree-house-storage

Usage

Middleware functions

multipartUpload(options)

Express middleware function to upload a local file using multer.

import { middleware } from '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

createFile(path, name, content)

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

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

readFile(path)

Read an existing local file via filepath. (Asynchronous)

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

deleteFile(path)

Delete an existing local file via filepath (Synchronous)

import { local } from '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 '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 'tree-house-storage'

const options = {
  path: 'localPath/localFile.png',
  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 } = amazon.uploadFile(client, options);

getPresignedUrl(client, options)

Gets a pre-signed url for an S3 resource

import { amazon } from 'tree-house-storage'

const options = {
  bucket: 's3bucketName',
  key: 's3KeyName',
  expires: 1600, // Optional expiration time
};
const { location, bucket, key } = amazon.getPresignedUrl(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

Keywords

tree House

FAQs

Package last updated on 09 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts