readTextFile() not working?

what is this? its there but its not working
No description
5 Replies
Deno AI Helper
Deno AI Helper9mo ago
I'm sorry to hear that you're having trouble with readTextFile(). This function is used to asynchronously read and return the entire contents of a file as an UTF-8 decoded string. If you're trying to read a directory, it will throw an error. Here's a basic usage example from the documentation:
const data = await Deno.readTextFile("hello.txt");
const data = await Deno.readTextFile("hello.txt");
This code reads a file named "hello.txt" and logs its contents to the console. Remember that this function is asynchronous, so you need to use await to wait for the promise to resolve. If you're still having trouble, could you please provide more details about the issue? For example: - What is the exact error message you're seeing? - Can you share the code that's causing the problem? - Are you sure the file you're trying to read exists and is accessible? - Did you provide the --allow-read flag when running your script? This is required to give Deno permission to read from the filesystem. These details will help me assist you better. 🦕
king8fisher9mo ago
I would suggest to try “./config.toml” Otherwise please provide more details Silencing the linter might have lead to an unnoticed type error
raunioroo9mo ago
^ what he said. The file path is relative to the current working directory of Deno, not to the calling script you can check what the working dir is with Deno.cwd();. If you really want to use script relative paths, import.meta.resolve("../hello.txt") might do the trick
ioB9mo ago
808s and heartbreaks