unfs

πŸ“ Unified Node.js fs-like API for cloud storage services

View the Project on GitHub AnandChowdhary/unfs

πŸ“ Unfs

Node.js API like fs, but for cloud storage services. If you’re used to doing fs.writeFile(), this should be easy.

Node CI Checks Coverage npm version Types Dependencies Dev dependencies Peer dependencies Install size License

☁️ Services

πŸ’‘ Usage

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));

βš’ Configuration

General

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
}));

Memory

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"
}));

πŸ“„ License

MIT Β© Anand Chowdhary