picasso-fs
v10.0.0
Published
A simple file system abstraction layer with promise-based functions.
Maintainers
Readme
easy-fs
A lightweight and simple wrapper for Node.js native fs module.
Designed to make file system operations like reading, writing, copying, removing, and watching files or directories more convenient.
Installation
npm install easy-fs
Usage
const fs = require("easy-fs");
// Write a JSON file
fs.write("data/user.json", { name: "John" });
// Read the file or folder
const user = fs.read("/data/user.json");
const folder = fs.read("/data");
// Remove file or folder
fs.remove("/data");
fs.remove("/data/user.json");
---
API Reference
write(filePath, data)
Writes content to a file. Creates the directories automatically if they don't exist.
filePath (string): Path to the file.
data (string | object): Content to write. If an object is passed, it will be stringified as JSON.
---
read(filePath)
Reads the content of a file or lists the contents of a directory.
filePath (string): Path to the file or folder.
Returns:
File content as string or parsed JSON.
An array of file/folder names if the path is a directory.
---
remove(filePath)
Deletes a file or directory (recursively and forcefully).
filePath (string): Path to remove.
---
copy(src, dest)
Copies a file from source to destination.
src (string): Source file path.
dest (string): Destination file path.
---
move(src, dest)
Moves (renames) a file from source to destination.
src (string): Source path.
dest (string): Destination path.
---
file(filePath, content = '')
Creates a new file with optional content.
filePath (string): Path to create the file.
content (string): Optional string content (default is empty).
---
list(folderPath)
Lists all files and folders inside a directory.
folderPath (string): Path to the directory.
Returns: An array of names inside the directory.
---
exists(path)
Checks whether a file or folder exists.
path (string): Path to check.
Returns: true or false.
---
watch(path)
Watches a file or directory for changes or deletion.
path (string): File or folder to watch.
Returns: An object containing:
onupdate(callback): Triggered when the file/directory is updated.
For directories: { path, items }
For files: { path, content }
ondelete(callback): Triggered when the file/folder is deleted.
{ path }
close(): Stops the watcher.
Example
const fs = require("easy-fs");
const watcher = fs.watch("./myfolder/");
watcher.onupdate = (e) => {
console.log("Updated:", e);
};
watcher.ondelete = (e) => {
console.log("Deleted:", e);
};
// Stop watching after 10 seconds
setTimeout(() => {
watcher.close();
}, 10000);
---
License
MIT
---