So after checking if any .xml files are present with the below code, how do I access the file? I need to access the file to parse the contents and display.
var fileWatcher = require("chokidar");
var watcher = fileWatcher.watch("./*.xml", {
ignored: /[\/\\]\./,
usePolling: true,
persistent: true,
});
// Add event listeners.
watcher.on("add", function (path) {
console.log("File", path, "has been added");
});
I'm assuming, based on chokidars docs that it's used to watch for file changes in a directory?
If you want to open a file in node js just use the filesystem ('fs') module.
EDIT: as a little extra you can enable async/await for fs
if you want to open file when its added you could do this