본문 바로가기

Back-End/Node.js

Node.js.23.Node.js에서 파일목록 알아내기

반응형

목표

main.js에서 파일 데이터를 추가하게 되면, list의 수정이 아주 빈번해질 것이다. 따라서 Nodejs를 이용하여 data폴더 안에 파일 목록을 알아내보자.

 


Google에 nodejs file list in directory 검색해보자.

 

How do you get a list of the names of all files present in a directory in Node.js?

I'm trying to get a list of the names of all the files present in a directory using Node.js. I want output that is an array of filenames. How can I do this?

stackoverflow.com

 

fs.readdir

//nodedir.js
const testFolder = './data';	//data폴더 안에 있는 파일들을 본다
var fs = require('fs');

fs.readdir(testFolder, function(err, filelist) {
  console.log(filelist);
});

 

반응형