Answers for "node js read files from directory"

3

how to get file name in directory node js

const fs = require('fs')

const dir = '/Users/flavio/folder'
const files = fs.readdirSync(dir)

for (const file of files) {
  console.log(file)
}
Posted by: Guest on October-16-2020
5

node js get files in dir

const path = require('path');
const fs = require('fs');

fs.readdir(
  path.resolve(__dirname, 'MyFolder'),
  (err, files) => {
    if (err) throw err;
    
    for (let file of files) {
      console.log(file);
    }
  }
);
Posted by: Guest on September-07-2020
2

how to get file name in directory node js

const path = require('path')

//...

//inside the `for` loop
const stat = fs.lstatSync(path.join(dir, file))
Posted by: Guest on October-16-2020

Code answers related to "node js read files from directory"

Code answers related to "Javascript"

Browse Popular Code Answers by Language