Installations
npm install nodejs-fs-utils
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.17.5
NPM Version
6.14.14
Score
87
Supply Chain
99
Quality
76
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
sergiu-gordienco
Download Statistics
Total Downloads
1,065,161
Last Day
1,167
Last Week
6,949
Last Month
14,917
Last Year
191,412
GitHub Statistics
12 Stars
38 Commits
4 Forks
1 Watching
2 Branches
2 Contributors
Bundle Size
16.51 kB
Minified
3.65 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.2.6
Package Id
nodejs-fs-utils@1.2.6
Unpacked Size
78.74 kB
Size
12.55 kB
File Count
21
NPM Version
6.14.14
Node Version
14.17.5
Publised On
30 Nov 2021
Total Downloads
Cumulative downloads
Total Downloads
1,065,161
Last day
38.4%
1,167
Compared to previous day
Last week
9.9%
6,949
Compared to previous week
Last month
-49.7%
14,917
Compared to previous month
Last year
14.8%
191,412
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
nodejs-fs-utils
NodeJs FileSystem (FS) extra utilities
Methods
- rmdirs - remove a file or folder even it isn't empty ( accept specifying logic for symlinks )
- rmdirsSync - synchronous version of rmdirs
- mkdirs - creates a folder and it parent if it is needed ( accept specifying logic for symlinks )
- mkdirsSync - synchronous version of mkdirs
- emptyDir - remove contents of a dir
- emptyDirSync - synchronous version of emptyDir
- isEmpty - return if file is empty or not
- isEmptySync - synchronous version of isEmpty
- remove - remove file, directory or link
- removeSync - synchronous version of remove
symbolicLinks
- treat symbolic links as files ( defaulttrue
)skipErrors
- skip errors just log them ( defaultfalse
)
- fsize - count file or folder size, has additional options
symbolicLinks
- treat symbolic links as files ( defaulttrue
)countFolders
- counts and folder inode size ( defaulttrue
)countSymbolicLinks
- counts symbolic links inode size ( defaulttrue
)logErrors
- log all error in an array ( defaultfalse
)skipErrors
- skip errors just log them ( defaultfalse
)
- fsizeSync - synchronous version of fsize
- move - move files or folders
- moveSync - synchronous version of move
symlinksKeep
- specify how to treat symlinks-
accepted values: *"file", "directory", "all"*
-
symlinksNormalize
- specify if is needed link normalizing-
accepted values: *"auto", "none", "relative", "absolute"*
-
linkFiles
- for files linking instead of coping-
accepted values: *"auto", "none", "relative", "absolute"*
-
symbolicLinks
- treat symbolic links as files ( defaulttrue
)countFolders
- counts and folder inode size ( defaulttrue
)countSymbolicLinks
- counts symbolic links inode size ( defaulttrue
)logErrors
- log all error in an array ( defaultfalse
)skipErrors
- skip errors just log them ( defaultfalse
)
- copy - copy files or folders
- copySync - synchronous version of copy
symlinksKeep
- specify how to treat symlinks-
accepted values: *"file", "directory", "all"*
-
symlinksNormalize
- specify if is needed link normalizing-
accepted values: *"auto", "none", "relative", "absolute"*
linkFiles
- for files linking instead of coping-
accepted values: *"auto", "none", "relative", "absolute"*
-
symbolicLinks
- treat symbolic links as files ( defaulttrue
)countFolders
- counts and folder inode size ( defaulttrue
)countSymbolicLinks
- counts symbolic links inode size ( defaulttrue
)logErrors
- log all error in an array ( defaultfalse
)skipErrors
- skip errors just log them ( defaultfalse
)
- walk - walk throuth files, folder and links ( advanced configurations )
- walkSync - synchronous version of walk
rmdirs
optional can be send fs module in
"fs"
option, P.S. it removes link files or directories.
1 var fsUtils = require("nodejs-fs-utils"); 2 3 //removing a folder 4 fsUtils.rmdirs("test/folder", function (err) { 5 // callback code 6 }); 7 8 // removing a folder and remove recursive in symbolic links 9 // treat the as folders if necessary 10 fsUtils.rmdirs("test/folder", function (err) { 11 // callback code 12 }, { 13 symbolicLinks : false 14 }); 15 16 // try to remove, skip errors 17 fsUtils.rmdirs("test/folder", function (err) { 18 // callback code 19 }, { 20 skipErrors : true 21 });
rmdirsSync
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // removing a folder 4 // symbolic links will be unlinked instead of removing files from them 5 fsUtils.rmdirsSync("test/folder"); 6 7 // removing a folder and remove recursive in symbolic links 8 // treat the symbolic links as folders if these links to directories 9 fsUtils.rmdirsSync("test/folder", { 10 symbolicLinks : false 11 }); 12 13 // try to remove, skip errors 14 fsUtils.rmdirsSync("test/folder", { 15 skipErrors : true 16 });
emptyDir
remove contents of a directory
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // removing folder's contents 4 fsUtils.emptyDir("test/folder", function (err) { 5 // callback code 6 });
emptyDirSync
remove contents of a directory, synchronous
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // removing folder's contents 4 fsUtils.emptyDirSync("test/folder");
isEmpty
checks if folder is empty
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // return state = true if folder is empty 4 fsUtils.isEmpty("test/folder", function (err, state) { 5 // callback code 6 });
isEmptySync
checks if folder is empty, synchronous
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // return state = true if folder is empty 4 fsUtils.isEmptySync("test/folder");
mkdirs - build a directory tree
optional can be send fs module in
"fs"
option
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // removing a folder 4 // the function will stop an exception on symlink detection 5 fsUtils.mkdirs("newfolder/folder/subfolder", function (err) { 6 // callback code 7 }); 8 9 // treat the symbolic links as folders if these links to directories 10 fsUtils.rmdirs("newfolder/folder/symbolic-link/subfolder", { 11 symbolicLinks : false 12 }, function (err) { 13 // callback code 14 });
mkdirsSync
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // removing a folder 4 // the function will throw an exception on symlink detection 5 fsUtils.mkdirs("newfolder/folder/subfolder"); 6 7 // treat the symbolic links as folders if these links to directories 8 fsUtils.rmdirs("newfolder/folder/symbolic-link/subfolder", { 9 symbolicLinks : false 10 });
remove
removing file or directories
removeSync
removing file or directories
fsize - advanced file size scan for links folders or files
optional can be send fs module in
"fs"
option
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // return file size 4 fsUtils.fsize("videos/video.mp4", function (err, size) { 5 // callback code 6 }); 7 8 9 // the function will stop on a symlink detection 10 fsUtils.fsize("newfolder/folder/subfolder", function (err, size) { 11 // callback code 12 }); 13 14 15 // treat the symbolic links as folders if these links to directories 16 fsUtils.fsize("newfolder/folder/symbolic-link/subfolder", { 17 symbolicLinks : false 18 }, function (err, size) { 19 // callback code 20 }); 21 22 23 // don't stop scanning on errors 24 fsUtils.fsize("newfolder/folder/symbolic-link/subfolder", { 25 skipErrors : true 26 }, function (err, size) { 27 // callback code 28 }); 29 30 31 // don't stop scanning on errors 32 // return an array of all errors 33 fsUtils.fsize("newfolder/folder/symbolic-link/subfolder", { 34 skipErrors : true, 35 logErrors : true 36 }, function (err, size) { 37 // callback code 38 }); 39 40 41 // don't count folders size 42 fsUtils.fsize("newfolder/folder/symbolic-link/subfolder", { 43 countFolders : false 44 }, function (err, size) { 45 // callback code 46 }); 47 48 49 // don't scan links and don't count links size 50 fsUtils.fsize("newfolder/folder/symbolic-link/subfolder", { 51 countSymbolicLinks : false 52 }, function (err, size) { 53 // callback code 54 });
fsizeSync - file or folder size synchronous
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // return file size 4 var size = fsUtils.fsizeSync("videos/video.mp4"); 5 6 7 // the function will stop on a symlink detection 8 var size = fsUtils.fsizeSync("newfolder/folder/subfolder", function (err, size) { 9 // callback code 10 }); 11 12 13 // treat the symbolic links as folders if these links to directories 14 var size = fsUtils.fsizeSync("newfolder/folder/symbolic-link/subfolder", { 15 symbolicLinks : false 16 }); 17 18 19 // don't stop scanning on errors 20 var config = { skipErrors : true }; 21 var size = fsUtils.fsizeSync("newfolder/folder/symbolic-link/subfolder", config); 22 if (config.errors.length) { 23 console.log("Error detected: ", config.errors[0]) 24 } 25 26 27 // don't stop scanning on errors 28 // return an array of all errors 29 var config = { skipErrors : true }; 30 var size = fsUtils.fsizeSync("newfolder/folder/symbolic-link/subfolder", config); 31 if (config.errors.length) { 32 console.log("Error detected: ", config.errors[0]) 33 } 34 35 36 // don't count folders size 37 var size = fsUtils.fsizeSync("newfolder/folder/symbolic-link/subfolder", { 38 countFolders : false 39 }); 40 41 42 // don't scan links and don't count links size 43 var size = fsUtils.fsizeSync("newfolder/folder/symbolic-link/subfolder", { 44 countSymbolicLinks : false 45 });
move
move file of folders or links
options for move function:
symlinksNormalize
- specify how to treat symlinks specify if is needed link normalizing accepted values:"auto"
,"none"
,"relative"
,"absolute"
"auto"
,"none"
or"absolute"
- uses absolute path"relative"
- uses relative paths for links P.S"auto"
will be dynamic in future, will try to use relative if it is posiblesymlinksKeep
- specify if is needed to keep simplinks or to move files or folders accepted values: "file", "directory", "all"linkFiles
- for files linking instead of moving accepted values: "auto", "none", "relative", "absolute"symbolicLinks
- treat symbolic links as files ( defaulttrue
)countFolders
- counts and folder inode size ( defaulttrue
)countSymbolicLinks
- counts symbolic links inode size ( defaulttrue
)logErrors
- log all error in an array ( defaultfalse
)skipErrors
- skip errors just log them ( defaultfalse
) P.S. if istrue
the errors will be an array
move examples:
moveSync examples:
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // move file or folders 4 fsUtils.move(__dirname + "/source", "./destination-path", function (err, cache) { 5 if (!err) { 6 console.log("Moved !"); 7 } else { 8 console.error("Error", err) 9 } 10 }); 11 12 // move files and skip errors 13 fsUtils.move(__dirname + "/source", "./destination-path", function (errors, cache) { 14 if (!errors.length) { 15 console.log("Moved !"); 16 } else { 17 errors.forEach(function (err) { 18 console.error("Error", err) 19 }); 20 } 21 }, { 22 skipErrors : true 23 }); 24
moveSync
synchronous version for move function
moveSync examples:
1 var fsUtils = require("nodejs-fs-utils"); 2 var moveSync = fsUtils.moveSync; 3 4 // move file or folders 5 moveSync(__dirname + "/source", "./destination-path", function (err, cache) { 6 if (!err) { 7 console.log("Moved !"); 8 } else { 9 console.error("Error", err) 10 } 11 }); 12 13 // move files and skip errors 14 moveSync(__dirname + "/source", "./destination-path", function (errors, cache) { 15 if (!errors.length) { 16 console.log("Moved !"); 17 } else { 18 errors.forEach(function (err) { 19 console.error("Error", err) 20 }); 21 } 22 }, { 23 skipErrors : true 24 }); 25
copy
copy file of folders or links
options for copy function:
symlinksNormalize
- specify how to treat symlinks specify if is needed link normalizing accepted values:"auto"
,"none"
,"relative"
,"absolute"
"auto"
,"none"
or"absolute"
- uses absolute path"relative"
- uses relative paths for links P.S"auto"
will be dynamic in future, will try to use relative if it is posiblesymlinksKeep
- specify if is needed to keep simplinks or to copy files or folders accepted values: "file", "directory", "all"linkFiles
- for files linking instead of coping accepted values: "auto", "none", "relative", "absolute"symbolicLinks
- treat symbolic links as files ( defaulttrue
)countFolders
- counts and folder inode size ( defaulttrue
)countSymbolicLinks
- counts symbolic links inode size ( defaulttrue
)logErrors
- log all error in an array ( defaultfalse
)skipErrors
- skip errors just log them ( defaultfalse
) P.S. if istrue
the errors will be an array
copy examples:
copySync examples:
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // copy file or folders 4 fsUtils.copy(__dirname + "/source", "./destination-path", function (err, cache) { 5 if (!err) { 6 console.log("Copied !"); 7 } else { 8 console.error("Error", err) 9 } 10 }); 11 12 // copy files and skip errors 13 fsUtils.copy(__dirname + "/source", "./destination-path", function (errors, cache) { 14 if (!errors.length) { 15 console.log("Copied !"); 16 } else { 17 errors.forEach(function (err) { 18 console.error("Error", err) 19 }); 20 } 21 }, { 22 skipErrors : true 23 }); 24 25 // link files instead of copying 26 fsUtils.copy(__dirname + "/source", "./destination-path", function (err, cache) { 27 if (!err) { 28 console.log("Files were linked !"); 29 } else { 30 console.error("Error", err) 31 } 32 }, { 33 linkFiles : "relative" 34 }); 35
copySync
synchronous version for copy function
copySync examples:
1 var fsUtils = require("nodejs-fs-utils"); 2 var copySync = fsUtils.copySync; 3 4 // copy file or folders 5 copySync(__dirname + "/source", "./destination-path", function (err, cache) { 6 if (!err) { 7 console.log("Copied !"); 8 } else { 9 console.error("Error", err) 10 } 11 }); 12 13 // copy files and skip errors 14 copySync(__dirname + "/source", "./destination-path", function (errors, cache) { 15 if (!errors.length) { 16 console.log("Copied !"); 17 } else { 18 errors.forEach(function (err) { 19 console.error("Error", err) 20 }); 21 } 22 }, { 23 skipErrors : true 24 }); 25 26 // link files instead of copying 27 copySync(__dirname + "/source", "./destination-path", function (err, cache) { 28 if (!err) { 29 console.log("Files were linked !"); 30 } else { 31 console.error("Error", err) 32 } 33 }, { 34 linkFiles : "relative" 35 }); 36
walk - walk throuth files folder and links ( advanced configurations )
optional can be send fs module in
"fs"
option cache reference can be used for storing data while walking
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // walk througth a list of files and folders in a folder 4 fsUtils.walk("./videos", function (err, path, stats, next, cache) { 5 // callback code 6 // ... 7 // stats.isDirectory() 8 // 9 // cache.errors is array of errors 10 // continue walk 11 next(); 12 }); 13 14 // walk througth a list of files and folders in a folder 15 fsUtils.walk("./videos", function (err, path, stats, next, cache) { 16 // callback code 17 // ... 18 // stats.isDirectory() 19 // 20 // cache.errors is array of errors 21 // continue walk 22 next(); 23 }, function (cache) { 24 console.log("Walk is finished"); 25 }); 26 27 28 // treat the symbolic links as folders if these links to directories 29 fsUtils.walk("newfolder/folder/symbolic-link/subfolder", { 30 symbolicLinks : false 31 }, function (err, path, stats, next, cache) { 32 // callback code 33 next(); 34 }); 35 36 37 // don't stop scanning on errors 38 fsUtils.walk("newfolder/folder/symbolic-link/subfolder", { 39 skipErrors : true 40 }, function (err, path, stats, next, cache) { 41 // callback code 42 next(); 43 }); 44 45 46 // don't stop scanning on errors 47 // return an array of all errors in cache reference 48 fsUtils.walk("newfolder/folder/symbolic-link/subfolder", { 49 skipErrors : true, 50 logErrors : true 51 }, function (err, path, stats, next, cache) { 52 // callback code 53 next(); 54 }, function (cache) { 55 if (cache.errors.length) { 56 console.log("Errors: ", cache.errors); 57 } else { 58 console.log("No errors found"); 59 } 60 }); 61
walkSync - walk sync throuth files folder and links ( advanced configurations )
walkSync
has same api aswalk
, but it is synchronous
1 var fsUtils = require("nodejs-fs-utils"); 2 3 // walk througth a list of files and folders in a folder 4 fsUtils.walkSync("./videos", function (err, path, stats, next, cache) { 5 // callback code 6 // ... 7 // stats.isDirectory() 8 // 9 // cache.errors is array of errors 10 // continue walk 11 next(); 12 }); 13 14 // walk througth a list of files and folders in a folder 15 fsUtils.walkSync("./videos", function (err, path, stats, next, cache) { 16 // callback code 17 // ... 18 // stats.isDirectory() 19 // 20 // cache.errors is array of errors 21 // continue walk 22 next(); 23 }, function (cache) { 24 console.log("Walk is finished"); 25 }); 26 27 28 // treat the symbolic links as folders if these links to directories 29 fsUtils.walkSync("newfolder/folder/symbolic-link/subfolder", { 30 symbolicLinks : false 31 }, function (err, path, stats, next, cache) { 32 // callback code 33 next(); 34 }); 35 36 37 // don't stop scanning on errors 38 fsUtils.walkSync("newfolder/folder/symbolic-link/subfolder", { 39 skipErrors : true 40 }, function (err, path, stats, next, cache) { 41 // callback code 42 next(); 43 }); 44 45 46 // don't stop scanning on errors 47 // return an array of all errors in cache reference 48 fsUtils.walkSync("newfolder/folder/symbolic-link/subfolder", { 49 skipErrors : true, 50 logErrors : true 51 }, function (err, path, stats, next, cache) { 52 // callback code 53 next(); 54 }, function (cache) { 55 if (cache.errors.length) { 56 console.log("Errors: ", cache.errors); 57 } else { 58 console.log("No errors found"); 59 } 60 });
walk - examples
getArray of folders in a array
1 var fsUtils = require("nodejs-fs-utils"); 2 // getArray of folders in a array 3 var folders = []; 4 fsUtils.walkSync("newfolder/folder/symbolic-link/subfolder", { 5 skipErrors : true, 6 logErrors : true 7 }, function (err, path, stats, next, cache) { 8 if (!err && stats.isDirectory()) { 9 folders.push(path); 10 } 11 next(); 12 });
remove folders with name "tmp"
1 var fsUtils = require("nodejs-fs-utils"); 2 var fs = require("fs"); 3 4 // synchronous 5 fsUtils.walkSync("newfolder/folder/symbolic-link/subfolder", { 6 skipErrors : true, 7 logErrors : true 8 }, function (err, path, stats, next, cache) { 9 if (!err && stats.isDirectory() && path.match(/\/tmp$/)) { 10 fs.unlinkSync(path); 11 } else { 12 next(); 13 } 14 }); 15 16 // asynchronous 17 fsUtils.walk("newfolder/folder/symbolic-link/subfolder", { 18 skipErrors : true, 19 logErrors : true, 20 stackPushEnd: true // push new observed files to end of the stack insteat of beginig 21 }, function (err, path, stats, next, cache) { 22 if (!err && stats.isDirectory() && path.match(/\/tmp$/)) { 23 fs.unlinkSync(path); 24 25 // for async to tell that step is done 26 // without this row onend callback will not be trigered 27 cache.count++; 28 } else { 29 next(); 30 } 31 }, function (cache) { // optional 32 console.log("Finished") 33 });
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
2.6
/10
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to nodejs-fs-utils
dir-fs-utils
A NodeJS library that creates several utility functions over the native fs module for directories
@alwatr/node-fs
Enhanced file system operations in Node.js with asynchronous queue to prevent parallel writes.
kurento-fs
kurento's nodejs of fs utils class
@alwatr/nanolib
Necessary library for all ECMAScript (JavaScript/TypeScript) projects.