Some utilities for Node.js
npm install https://github.com/SylvainTirreau/nodeJSUtils
Lazy to register a npm package.
Simple version of the Python walkAsync function to get all directories and files in a folder.
As the Python walk function, for each directory in the tree rooted at directory, it yield an array [dirpath, dirnames, filenames].
import { os } from 'nodejsutils'
// or
// import { walkAsync as walk } from 'nodejsutils/utils/os'
import {join} from 'path'
const readSrc = async (): Promise<void> => {
for await (const [root, dirs, files] of os.walkAsync('./src')) {
for (const name of files) {
console.log(join(root, name))
}
for (const name of dirs){
console.log(join(root, name))
}
}
}
void readSrc()
import { os } from 'nodejsutils'
// or
// import { walkSync as walk } from 'nodejsutils/utils/os'
import {join} from 'path'
for (const [root, dirs, files] of os.walkSync('./src')) {
for (const name of files) {
console.log(join(root, name))
}
for (const name of dirs){
console.log(join(root, name))
}
}