fsmate
Version:
A lightweight Node.js library for working with the file system (fs) in a simplified way.
238 lines (157 loc) โข 5.21 kB
Markdown
# fsMate
fsMate A modular collection of file system utilities for Node.js
[](https://www.npmjs.com/package/fsmate)


[](https://www.jsdelivr.com/package/npm/fsmate)
[](https://www.npmjs.com/package/fsmate)
It simplifies working with files and directories by providing a higher-level, promise-based API for common file operations such as checking access permissions, creating files/directories, copying files, and mirroring directories.
> ๐ง Author: Indian Modassir
> ๐
Date: 26-07-2025
> ๐ฆ Repository: [https://github.com/jsvibe/fsMate](https://github.com/jsvibe/fsMate)
## ๐ Features
- Sync and async file system methods with smart detection
- Check file or directory accessibility (read/write/execute)
- Create files and directories safely
- Copy and mirror directories with override control
- Generate temporary file/directory names
- Fully promise-based where appropriate
## ๐ฆ Installation
```bash
npm install fsmate
```
## ๐ Usage
```js
const fsMate = require('fsmate');
// Example: Create a directory recursively
fsMate.mkdir(['./example/nested/dir'])
.then(() => console.log("Directory created"))
.catch(console.error);
// Example: Copy file
fsMate.copy('./source.txt', './dest.txt', true)
.then(() => console.log("File copied"))
.catch(console.error);
```
## ๐ API Reference with Examples
### `fsMate.tmpName(prefix)`
Generates a temporary, obfuscated file or directory name using a given prefix.
```js
const fsMate = require('fsmate');
const tempPath = fsMate.tmpName('/tmp');
console.log(tempPath); // Example output: /tmp/.!qK9p
```
### `fsMate.AutoSync(methodName, ...args, [callback])`
Dynamically calls an `fs` method in async mode (if a callback is given) or sync mode otherwise.
```js
// Async usage
fsMate.AutoSync('readFile', 'example.txt', 'utf8', (err, data) => {
if (!err) console.log(data);
});
// Sync usage
const content = fsMate.AutoSync('readFile', 'example.txt', 'utf8');
console.log(content);
```
### `fsMate.isFile(path, [callback])`
Checks if the path points to a file.
```js
// Sync
const isFile = fsMate.isFile('./data.txt');
console.log(isFile); // true or false
// Async
fsMate.isFile('./data.txt', (result) => {
console.log(result); // true or false
});
```
### `fsMate.isDir(path, [callback])`
Checks if the path points to a directory.
```js
fsMate.isDir('./some-folder', (result) => {
console.log(result); // true or false
});
```
### `fsMate.access(path, mode, [callback])`
Checks whether a file or directory is accessible with a specific mode.
```js
fsMate.access('./file.txt', fs.constants.R_OK, (accessible) => {
console.log(accessible); // true or false
});
```
### `fsMate.isReadable(path, [callback])`
Checks if the path is readable.
```js
fsMate.isReadable('./file.txt', (readable) => {
console.log(readable); // true or false
});
```
### `fsMate.isWritable(path, [callback])`
Checks if the path is writable.
```js
fsMate.isWritable('./file.txt', (writable) => {
console.log(writable); // true or false
});
```
### `fsMate.isExecutable(path, [callback])`
Checks if the path is executable.
```js
fsMate.isExecutable('./script.sh', (executable) => {
console.log(executable); // true or false
});
```
### `fsMate.mkdir(paths, [mode])`
Creates directories recursively.
**`paths`** can be a single path or an array.
```js
fsMate.mkdir(['./logs/app', './temp/cache'])
.then(() => console.log("Directories created"))
.catch(console.error);
```
### `fsMate.mkFile(paths, [override])`
Creates empty files. If `override` is false, existing files are left untouched.
```js
fsMate.mkFile(['./output.txt'], true)
.then(() => console.log("File created"))
.catch(console.error);
```
### `fsMate.copy(originPath, targetPath, [override])`
Copies a file from source to destination. If `override` is false and target exists, it skips.
```js
fsMate.copy('./input.txt', './backup/input.txt', true)
.then(() => console.log("File copied"))
.catch(console.error);
```
### `fsMate.mirror(originDir, targetDir, [override])`
Recursively mirrors one directory into another.
```js
fsMate.mirror('./sourceDir', './destinationDir', true)
.then(() => console.log("Directory mirrored"))
.catch(console.error);
```
## ๐ License
MIT License.
ยฉ 2025 Indian Modassir
## ๐ Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
## ๐งช Tests
Currently, no test suite is included. Basic testing can be done manually via example scripts. A test suite will be added in future releases.
## ๐ Links
- GitHub: [https://github.com/jsvibe/fsMate](https://github.com/jsvibe/fsMate)