Node.js API like fs
, but for cloud storage services. If you're used to doing fs.writeFile()
, this should be easy.
- AWS S3
- Azure Storage
- Google Cloud Storage
- Firebase Cloud Storage
- Memory file system
- In memory (for testing only)
Install the package from npm:
npm install unfs
With TypeScript or ES6 async modules:
import Unfs from "unfs";
const fs = new Unfs({
service: "s3",
bucket: "s3-bucket-name",
auth: {}
}));
const url = await fs.writeFile("message.txt", "Hello, world");
console.log("url", url);
With Node.js using the Promise API:
const Unfs = require("unfs");
const fs = new Unfs({
service: "s3",
bucket: "s3-bucket-name",
auth: {}
});
fs.writeFile("message.txt", "Hello, world")
.then(url => console.log("url", url))
.catch(error => console.error("error", error));
The following constructor properties can be used in all services:
const fs = new Unfs({
service: "your-service-here", // Select a service from below
prefix: "prefix_", // Add prefix to file name before saving
suffix: "_suffix", // Add Suffix to file name before saving
softDelete: true // Set to `true` to rename instead of deleting files,
deletePrefix: "deleted_" // Use with `softDelete` as file prexix
}));
Note: You should only use the Memory service in development, since you'll end up using lots of RAM when storing binary files in memory.
const fs = new Unfs({
service: "memory"
}));