// v1 - standalone usage:
const fs = require("fs");
const targetDir = "./";
fs.readdir(targetDir, (err, files) => {
files.forEach((file) => {
console.log(file);
});
});
// -----
// v2 - async for code useage
const fs = require("fs");
const listDirectory = (targetDir = "./") =>
new Promise((res, rej) =>
fs.readdir(targetDir, (err, files) => (err ? rej(err) : res(files)))
);
listDirectory()
.then(console.log)
.catch(console.log);
// -----
// v3 - Synchron:
const fs = require("fs");
const listDirectory = (targetDir = "./") => fs.readdirSync(targetDir);
console.log(listDirectory());
-
Notifications
You must be signed in to change notification settings - Fork 0
Useful Code snippets for daily tasks
License
cafedx/awesome-js-code-snippets
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Useful Code snippets for daily tasks
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published