node-fstab v1.0.16
node-fstab
by Moe Alam, Shinobi Systems
Currently for internal use at Shinobi Systems and is included in ShinobiCCTV software.
The node-fstab module provides a suite of tools for managing filesystem mounts in a Unix-like environment using Node.js. It includes functions to create mount points, mount/unmount filesystems, update and remove entries in /etc/fstab
, list mounts, and retrieve disk usage information.
Installation
npm install node-fstab
Usage
Importing the Module
const { createMountPoint, mount, update, remove, list, remountAll, remount, unmount, getDiskUsage, writeReadStream, checkDiskPathExists, execAsync } = require('node-fstab');
Functions
createMountPoint(path)
Creates a directory for a mount point if it doesn’t already exist.
path
: String - Path of the mount point.- Returns: An object with
ok
status anderror
message if any.
mount(server, remotePath, localPath, type = 'cifs', options = 'username=username,password=password')
Mounts a filesystem (e.g., CIFS or NFS) with customizable options.
server
: String - The server IP or hostname.remotePath
: String - The remote directory to mount.localPath
: String - The local mount point path.type
: String - Filesystem type (default: 'cifs').options
: String - Mount options, such as credentials.
update(sourceTarget, localPath, mountType = 'cifs', fstabOptions = 'username=username,password=password,rw,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0')
Updates or adds an entry in /etc/fstab
. Removes any existing entry with the same localPath
before appending a new entry.
sourceTarget
: String - The source device or server path.localPath
: String - The mount point on the local system.mountType
: String - Type of filesystem (e.g., 'cifs').fstabOptions
: String - Mount options to be used in/etc/fstab
.
remove(localPath)
Removes a mount entry from /etc/fstab
based on localPath
.
localPath
: String - The mount point path to remove from/etc/fstab
.
list()
Lists all entries in /etc/fstab
as an array of objects.
- Returns: An array of objects, each with
device
,mountPoint
,type
, andoptions
.
remountAll()
Remounts all filesystems listed in /etc/fstab
.
- Returns: An object with
ok
status and message upon completion.
remount(mountPath)
Remounts a specific mount point defined in /etc/fstab
.
mountPath
: String - Path of the mount point to remount.
unmount(localPath)
Unmounts a specified mount point.
localPath
: String - The local path to unmount.
getDiskUsage()
Provides disk usage information using df -h
as an array of objects.
- Returns: An array of objects, each with fields from
df -h
such asfilesystem
,size
,used
,avail
,use%
, andmounted
.
checkDiskPathExists(localPath)
Checks if a specific path exists among the mounted filesystems.
localPath
: String - The path to check.
writeReadStream(readerStream, outputFile)
Pipes data from a read stream to an output file with error handling.
readerStream
: Stream - The read stream to pipe data from.outputFile
: String - The output file to write data to.
Examples
Mount a CIFS Share
const { mount } = require('node-fstab');
(async () => {
const server = '192.168.1.200';
const remotePath = '/shared/folder';
const localPath = '/mnt/cifs_share';
const options = 'username=myuser,password=mypass';
const response = await mount(server, remotePath, localPath, 'cifs', options);
if (response.ok) {
console.log(`Mounted CIFS share at ${localPath}`);
} else {
console.error(`Error: ${response.error}`);
}
})();
License
This project is licensed under the MIT License.
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago