# tree-house-storage

> Tree House Storage

Latest version **1.0.2** (published 2019-04-09) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install tree-house-storage
pnpm add tree-house-storage
yarn add tree-house-storage
bun add tree-house-storage
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-04-09 |
| First published | 2019-04-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 4 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 (+13 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | ben-vr, dgyesbreghs, knor-el-snor, octagonal, willemhorsten |
| Keywords | tree House, treehouse, treehouse storage, treehouse storage |

## Links

- npm: https://www.npmjs.com/package/tree-house-storage
- Repository: git@github.com/icapps/tree-house-storage
- Homepage: https://github.com/icapps/tree-house-storage/issues#readme
- Issues: https://github.com/icapps/tree-house-storage/issues
- npm.io page: https://npm.io/package/tree-house-storage

## Dependencies (4)

- [multer](https://npm.io/package/multer.md) ~1.4.1
- [aws-sdk](https://npm.io/package/aws-sdk.md) ~2.437.0
- [tree-house](https://npm.io/package/tree-house.md) ~3.4.2
- [tree-house-errors](https://npm.io/package/tree-house-errors.md) ~1.2.2

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-04-09
- 1.0.1 — 2019-04-04

## README

# Treehouse storage

NodeJS storage utility module written in Typescript

[![npm version](https://badge.fury.io/js/tree-house-storage.svg)](https://badge.fury.io/js/tree-house-storage)
[![Dependencies](https://david-dm.org/icapps/tree-house-storage.svg)](https://david-dm.org/icapps/tree-house-storage.svg)
[![Build Status](https://travis-ci.org/icapps/tree-house-storage.svg?branch=master)](https://travis-ci.org/icapps/tree-house-storage)
[![Coverage Status](https://coveralls.io/repos/github/icapps/tree-house-storage/badge.svg)](https://coveralls.io/github/icapps/tree-house-storage) [![Greenkeeper badge](https://badges.greenkeeper.io/icapps/tree-house-storage.svg)](https://greenkeeper.io/)

## Installation

Install via npm

```shell
npm install tree-house-storage
```

or via yarn

```shell
yarn add tree-house-storage
```

## Usage

## Middleware functions

### multipartUpload(options)

Express middleware function to upload a local file using multer.

```javascript
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](https://github.com/expressjs/multer)

## Local filesystem

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

[More information on fs](https://nodejs.org/api/fs.html)

### createFile(path, name, content)

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

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

### readFile(path)

Read an existing local file via filepath. (*Asynchronous*)

```javascript
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*)

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

## Amazon

Amazon S3 libs

[More information on AWS S3](https://aws.amazon.com/sdk-for-node-js/)

### createClient(clientOptions)

Create an S3 client

```javascript
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

```javascript
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

```javascript
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](https://jestjs.io/docs/en/getting-started) 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:

- web: [https://github.com/icapps/tree-house-storage/issues](https://github.com/icapps/tree-house-storage/issues)

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](https://github.com/icapps/tree-house-storage/contributors) who participated in this project.

## License

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

---
_Source: https://npm.io/package/tree-house-storage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
