Node文件夹目录读取 const http = require('http')const fs = require('fs')/** * 读取文件夹名称 , 返回文件夹名称 */http.createServer((req, res) = { res.writeHead(200, {"Content-Type":"text/html;charset=UTF8"}); if (req.url
const http = require('http') const fs = require('fs') /** * 读取文件夹名称 , 返回文件夹名称 */ http.createServer((req, res) => { res.writeHead(200, {"Content-Type":"text/html;charset=UTF8"}); if (req.url == '/favicon.ico') { return; } fs.readdir('./Files/', (err, files) => { let wenjianjia = []; (function iterator(i) { if (i == files.length) { console.log(wenjianjia); return; } fs.stat('./Files/' + files[i], (err, stats) => { if (stats.isDirectory()) { wenjianjia.push(files[i]); } iterator(i + 1) }) })(0); }) res.end(); }).listen(3000, () => { console.log('服务器创建成功, 地址是http://localhost:3000'); })