Registry / storage / file-manager

file-manager

JSON →
library2.0.1jsnpmunverified

A minimal abstraction layer for file storage that defaults to local disk but can be overridden via event handlers for custom backends like databases. Version 2.0.1 is the current stable release; the package is in maintenance mode with infrequent updates. Unlike cloud-centric storage libraries, it remains simple and synchronous in intent for Node.js projects needing local file I/O with optional extensibility.

npm install file-manager
INSTALL
IMPORT
SIG · FILE-MANAGER
F
file-manager
storagejavascriptv2.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FileManager
const FileManager = require('file-manager')
import FileManager from 'file-manager'
This package uses CommonJS. No default ESM export exists.
new FileManager(path)
let manager = new FileManager(Path.join(__dirname, 'data'))
let manager = FileManager(Path.join(__dirname, 'data'))
FileManager is a constructor and must be instantiated with 'new'.
saveFile
manager.saveFile('file.txt', Buffer.from('hello')).then(() => console.log('saved'))
manager.saveFile('file.txt', 'hello', () => console.log('saved'))
saveFile returns a Promise, not a callback. The second argument must be a Buffer or string convertible to Buffer.

Shows basic file save/read operations and event-based custom handler registration for alternative storage backends.

const FileManager = require('file-manager'); const Path = require('path'); let manager = new FileManager(Path.join(__dirname, 'data')); // Save a file manager.saveFile('test.txt', Buffer.from('Hello, world!')) .then(() => console.log('Saved')) .catch(err => console.error(err)); // Read a file manager.readFile('test.txt') .then(contents => console.log(contents.toString())) .catch(err => console.error(err)); // Use event handlers for custom storage (e.g., database) manager.on('save', (filename, contents, callback) => { // custom save logic callback(null); }); manager.on('read', (filename, callback) => { // custom read logic callback(null, Buffer.from('data')); });
Debug
Known issues
gotchaIf storage directory is null and no save/read handlers are registered, isEnabled() returns false.
fix
Either provide a valid storage directory or register event handlers before calling methods.
affects: >=1.0.0
gotchasaveFile expects contents to be a Buffer; if a string is passed, it will be converted to Buffer using .toString() then interpreted as UTF-8, which may produce unexpected results for non-string types.
fix
Always pass a Buffer explicitly if you need precise control over encoding.
affects: >=1.0.0
gotchareadFiles never rejects, but individual file errors appear in the result array; check for error property on each result.
fix
Iterate over the array returned by readFiles and inspect each object's error field.
affects: >=1.0.0
gotchaSetting directory property after construction does not move existing files; it only affects future operations.
fix
Ensure directory is set correctly at construction or handle file migration separately.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: FileManager is not a constructor
FileManager was imported incorrectly or used without 'new'.
fix
Use: const FileManager = require('file-manager'); let manager = new FileManager(directory);
Error: ENOENT: no such file or directory, open '...'
The storage directory does not exist.
fix
Create the directory manually or use fs.mkdirSync before constructing FileManager.
TypeError: contents is not a buffer
The contents argument to saveFile was not a Buffer or convertible string.
fix
Pass a Buffer: Buffer.from(data) or string that can be converted via .toString().
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
30 hits · last 30 days
node
28
OpenAI (training)
1
Resources
file-manager — npm install file-manager · libregistry