typefs
TypeScript icon, indicating that this package has built-in type declarations

2.0.77 • Public • Published

Type FS

The single way to manipulate files in NodeJS. With Type FS you can define multiple disk locations across common protocols such as file:// or s3://. Use the disk manager to manipulate files located in disks.

Project Status

npm (tag) Node.js CI CodeQL codecov CodeFactor npms.io (quality)

Please refer to the roadmap to get the current progress of feature requests and bug fixes.

Why Type FS

  • Write automation scripts to manage files in many storage locations.
  • In your web application, restrict access to directories in your filesystem.
  • Keep your code readable. No callback hell, No excess promises.
  • You only have to learn one set of methods.
  • Supports JSON, TypeScript, or JavaScript configuration files.
  • Can be configured via environment variables to change the storage configuration.

Installation

In your project folder, run the following command:

npm install typefs
# npm install typefs-s3-driver

Example

// index.ts
import { Storage, Configuration, S3Disk } from 'typefs';
// import { S3Factory } from 'typefs-s3-driver';

// Storage.registerDriver('s3', S3Factory)

Storage.config: Configuration = {
    default: 'assets',
    disks: {
        tmp: {
            driver: 'file',
            root: '/tmp/',
            jail: true,
        },
        app: {
            driver: 'file',
            root: '/app/',
            jail: true,
        },
        assets: {
            driver: 'file',
            root: '/app/public/assets/',
            jail: true,
        },
//        s3: {
//            driver: 's3',
//            root: '/',
//            jail: true,
//            "bucket": process.env.S3_BUCKET || 'my-s3-bucket',
//            "endPoint": process.env.S3_ENDPOINT || 's3.amazonaws.com',
//            "accessKey": process.env.S3_ACCESS_KEY || 'minio-access-key',
//            "secretKey": process.env.S3_SECRET_KEY || 'minio-secret-key',
//       }
    }
}


const logoPng: Buffer = await Storage.disk().read('logo.png');

Documentation

Contribute

Package Sidebar

Install

npm i typefs

Weekly Downloads

17

Version

2.0.77

License

MIT

Unpacked Size

44.4 kB

Total Files

20

Last publish

Collaborators

  • daniel-samson