NodeJS: Difference between revisions

368 bytes added ,  3 September 2019
no edit summary
No edit summary
No edit summary
Line 34: Line 34:
===fs-extra===
===fs-extra===
[https://www.npmjs.com/package/fs-extra fs-extra] adds additional commands for accessing the filesystem such as copying and moving files.
[https://www.npmjs.com/package/fs-extra fs-extra] adds additional commands for accessing the filesystem such as copying and moving files.
<syntaxhighlight lang="js">
const fs = require('fs-extra')
// Synchronous functions
// Remove file or folder (rm -rf)
// Does nothing if path doesn't exist
fs.removeSync('/tmp/fileOrFolder');
// Creates a directory if it doesn't exist
// This example will create folder1 and folder2 if they don't exist
fs.ensureDirSync('/tmp/folder1/folder2/');
</syntaxhighlight>