The single way to manipulate files in NodeJS. With Type FS you can define multiple disk locations across common protocols such as file:https:// or s3:https://. Use the disk manager to manipulate files located in disks.
Please refer to the roadmap to get the current progress of feature requests and bug fixes.
- 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.
In your project folder, run the following command:
npm install typefs@^2.0.0
# npm install typefs-s3-driver
// 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');