1

I'm making a file manager using NodeJS and EJS, I have a default /folders route which reads all files and folders in a specific location using fs.readdirSync(folderPath, { withFileTypes: true }); and another route /create-folder makes me a new folder using fs.mkdirSync(folderPath, {recursive:true});

the thing is while the changes are reflected on the actual OS's file system instantly - the folder & files are created successfully - it doesn't show on the web app using the mentioned fs.readdirSync() in the /folders route, I need to restart the application to be able to see them, and since it's a file manager I need to see my created files & folders immediately, is it a caching issue, and if so how can I disable it?

1 Answers1

1

After debugging again I noticed that the fs module reads the data instantly as it is meant to be, and the logical error was in filtering those folders based on a Mongoose query fetched a step before and its result doesn't have the newly created folder name - which I insert it into the document when creating -, so after re-fetching the user's created folders again, it all worked.