简体   繁体   中英

Get List of all server files in a directory in Node.js

Any one here can help me out to rite a code to fetch List of all server files in a directory using Node.js

Just like it is done locally for system file

const testFolder = './models/';
const fs = require('fs');

fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {
    console.log(file);
  });
});

You can try this code to read all files present inside a directory.

 fs.readdirSync(`foldername`).forEach(function (file) {
  console.log(file);
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM