abiA
Denoβ€’3y agoβ€’
10 replies
abi

Simpler way to read a file relative to current module?

So I wrote a little helper function for reading the text content of a file relative to the current module. I came up with the following, but is there any simpler way that I'm missing? It seems a bit wordy πŸ˜„

import * as path from "std//path/mod.ts";

const gql = (filename: string) =>
  Deno.readTextFileSync(
    path.resolve(
      path.dirname(path.fromFileUrl(import.meta.url)),
      filename,
    ),
  );
Was this page helpful?