D
Deno

help

Simpler way to read a file relative to current module?

Aabi3/28/2023
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,
),
);
import * as path from "std//path/mod.ts";

const gql = (filename: string) =>
Deno.readTextFileSync(
path.resolve(
path.dirname(path.fromFileUrl(import.meta.url)),
filename,
),
);
UUUnknown User3/28/2023
2 Messages Not Public
Sign In & Join Server To View
Aabi3/28/2023
Ah, thanks a lot ๐Ÿ™‚
UUUnknown User3/28/2023
Message Not Public
Sign In & Join Server To View
Sร“scar3/28/2023
even simpler: import.meta.resolve(filename)
UUUnknown User3/28/2023
Message Not Public
Sign In & Join Server To View
Aabi3/28/2023
That's a good one, but I think it will only resolve modules, not any file
UUUnknown User3/28/2023
Message Not Public
Sign In & Join Server To View
Sร“scar3/28/2023
It resolves any URL and take into account the import_map.
UUUnknown User3/30/2023
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

Recommended Posts
error: BadResource: Bad resource IDI'm writing tests for https://github.com/deno-libs/tinyhttp/pull/9. ```js import { describe, expectRecent deployment not working?Hi there I have an api that was working just fine not sure what happen but new deployments are not wHow do you get the path to a file relative to the module which is referencing it?```ts const GET_PROGRAM_QUERY = Deno.readFileSync("./GetProgram.gql"); ``` GetProgram.gql is a fileInvestigating memory leak after adding new app dependencyHi, I added an OpenTelemetry metrics reporting loop to a Deno program and found that Deno began leakVScode deno lint blew up again after update.It seems every time there's an extension update VScode lint blows up and will stop recognizing top limport cache not workingI can't install cache of my http imports:Why isn't this error caught?Basic code example: ``` try { Deno.remove("fakefile"); } catch (err) { console.log("File doesn'tUsing dynamic import with npm compatibility gives intermittent error "__DENO_NODE_GLOBAL_THIS_167935This is pretty hard to google because the number at the end of the error changes everytime it happenGraphql codegendoes anyone have a solution to generate the sdk using graphq-request with Deno?Deno Third Party Modules Web HooksIs there a way to see the webhook payload URL a package you have published is listening for?Does Deno Deploy support location based analytics?The free version does not seem to support it. Does the paid version support it?IPC solution for a process manager๐Ÿ‘‹ I'm at day 7 of working on Pup (https://github.com/hexagon/pup) - a universal process manager rSpecifying config remotely or jsx on installI'm struggling quite a lot here. I originally recommended using this command: ```bash deno install -Is it possible to know what version of a dynamically-imported module was just imported?Right now, you can run code like `import('npm:lodash')`, which will get the latest version of lodashWhy am I getting an "Uncaught DOM Exception" in the Deno CLI?To replicate: 1. `deno` in the command line to initialize a Deno REPL ``` // Get an array of random Better way to allow downloading of files besides serving entire fileI'm trying to allow users to download files that are in a private folder which cannot be accessed puShare state between islandsHi. How could I share state between island. E.g. shopping cart. I click on add product and in some oIslands not working with Cloudflare DNS proxyI have deployed Deno on a remote server with nginx-ingress-controller that offers self-signed certifUpdate sub-directory for module already added to deno.land/xThe title pretty much says it all, but the module in question is `hot_mod`, and the current subdir iShould we, or how should we, use Deno as a sandbox for untrusted code?I've been using Deno in this context because of some of the nice security model features. However, i