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.
Please refer to the roadmap to get the current progress of feature requests and bug fixes.
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');