untitled.
untitled.•15mo ago

readTextFile() not working?

what is this? its there but its not working
No description
5 Replies
Deno AI Helper
Deno AI Helper•15mo 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");
console.log(data);
const data = await Deno.readTextFile("hello.txt");
console.log(data);
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. 🦕
king8fisher
king8fisher•15mo ago
I would suggest to try “./config.toml” Otherwise please provide more details Silencing the linter might have lead to an unnoticed type error
raunioroo
raunioroo•15mo 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
ioB
ioB•15mo ago
^^^
untitled.
untitled.OP•15mo ago
fixed.

Did you find this page helpful?