I have a code, it shows folders, I can navigate through them and files too, but this only works in the console:
`
const fs = require('fs/promises');
const fsToRead = require('fs')
const path = require('path');
const inquirer = require('inquirer');
const yargs = require('yargs');
const { lstatSync, readdirSync } = require('fs');
const http = require('http');
const url = require('url');
const options = yargs
.options('p', {
describe: 'Pattern',
default: ''
})
.options('d', {
describe: 'Path to directory',
default: process.cwd()
}).argv;
console.log(options);
class itemsList {
constructor(path, fileName) {
this.path = path;
this.fileName = fileName;
}
get folders() {
return lstatSync(this.path).isDirectory();
}
}
let executionDir = process.cwd();
const start = async () => {
const list = await fs.readdir(executionDir);
const items = list.map(fileName =>
new itemsList(path.join(executionDir, fileName), fileName));
const item = await inquirer.prompt([
{
name: 'fileName',
type: 'list',
message: `Choose: ${executionDir}`,
choices: items.map(item => ({name: item.fileName, value: item})),
}
]).then(answer => answer.fileName);
if (item.folders) {
executionDir = item.path;
return await start();
} else {
const data = await fs.readFile(item.path, 'utf-8');
if (!options.p) {
console.log(data)
}
else {
const regExp = new RegExp(options.p, 'igm');
console.log(data.match(regExp));
}
}
}
start();
`
HOW TO IMPLEMENT THAT SHE SHOWS ON THE PAGE OF THE BROWSER, THAT IN THE WEB VERSION I COULD GO TO THE FOLDERS, IF THIS IS A FILE SHE WOULD SHOW ITS CODE, I WOULD NOT HAPPEN IT!