Hello, I am having troubles from retrieving a filename from Templater using the user functions feature. This script works from the terminal but it stops working when I try running it from Obsidian using Templater. I would appreciate any help
Here is my code below
const fs = require("fs");
const path = require("path");
const journalPath = path.resolve("../Journal/");
function getLatestJournalEntry() {
const files = [];
fs.readdirSync(journalPath, { withFileTypes: true}).forEach(item => {
if (item.isFile()) { files.push(item.name) }
});
files.sort();
let lastEntry = files.slice(-1)[0];
lastEntry = lastEntry === undefined ? "No Last Entry -_-" : path.parse(lastEntry).name;
return lastEntry;
}