nicetomytyuk
nicetomytyuk2y ago

readFile path not found

I'm trying to use Deno.readFile but when is execute i get an error about wrong path. The files are like this: - db - dataservice.ts - config.sql - index.ts Then in daatabservice I try: private async getConfig(): Promise<string> { const decoder = new TextDecoder("utf-8"); const bytes = await Deno.readFile("./config.sql"); return decoder.decode(bytes); } Error handling product request: NotFound: Impossibile trovare il percorso specificato. (os error 3): readfile './config.sql' at async Object.readFile (e:\GitHub\GAB-Servizi-SB\eno_fs\30_fs.js:842:18)
7 Replies
raunioroo
raunioroo2y ago
It's relative to current working dir (Deno.cwd), not module location. "./db/config.sql" might work in your case, depending on how you start deno.
nicetomytyuk
nicetomytyukOP2y ago
I start Deno in debug with F5 on VS Code It is run like: deno.EXE run --inspect-wait --allow-all .\docker\volumes\functions\cloud\index.ts
raunioroo
raunioroo2y ago
You can create a module relative path by reading import.meta.url or something like that to get the module location, and use that to create an absolute path. I'm on mobile so can't dig an actuual example If i remember correctly, import.meta might even have a utility method to create a module-relative path that readFile can use. Or make it manually from import.meta.url
nicetomytyuk
nicetomytyukOP2y ago
Yeah I've just resolve it with import.meta
nicetomytyuk
nicetomytyukOP2y ago
I've use it like this:
No description
raunioroo
raunioroo2y ago
The first dot here on the path should be the working directory. So looks like you'd need to include that whole ". /docker/volumes/..." thing, if you don't use the module relative thing
nicetomytyuk
nicetomytyukOP2y ago
Thank you raunioroo ❤

Did you find this page helpful?