D
Deno

help

How to get `require.main.filename` like Node as Deno

Oocto312/17/2023
I am making a module to be published on deno.land/x. I want the user to put a file describing the configuration for the module on the same level as the entrypoint file. I could not figure out how to get the entrypoint filename from the module side. In Node.js, require.main.filename seems to solve this. How would this be appropriate to write in Deno?
JHJoe Hildebrand12/17/2023
import.meta.main is a boolean
Oocto312/17/2023
Thanks @Joe Hildebrand san However, A does not satisfy the requirement. What we want to know is not whether the script we are running is main, but the path of the main file.
JHJoe Hildebrand12/17/2023
Say more about what you're trying to accomplish?
Oocto312/17/2023
@Joe Hildebrand I will list examples of what I would like to do. I hope this gets the message across. - User imports my public module from deno.land/x into app.ts - When executed, the module will explore the expansion directory in the same hierarchy as app.tsx. - If the expansion directory does not contain the desired file, the module will provide functionality with default parameters. We want to get the path to app.ts to make this work.
JHJoe Hildebrand12/17/2023
Thank you, that makes sense. I will think about this some (maybe someone else can help as well)
Oocto312/17/2023
Thankyou @Joe Hildebrand san. This will be an extension mainly for Fresh. So the goal is to get the exact path of main.ts.
Ssyhol12/17/2023
Does this fulfill your requirements https://deno.land/api@v1.38.5?s=Deno.mainModule Deno.mainModule
The URL of the entrypoint module entered from the command-line. It requires read permission to the CWD.
Deno
Deno.mainModule | Runtime APIs | Deno
The URL of the entrypoint module entered from the command-line. It requires read permission to the CWD.
Jjcayzac12/18/2023
oh this is nice! I like const isRepl = Deno.mainModule.split('/').slice(-1)[0] === '$deno$repl.ts' to detect the repl (I wonder what Deno.mainModule returns in the Jupyter kernel… 🤔 )
Oocto312/18/2023
Thank you @Syhol san. This seems to solve the problem.

Looking for more? Join the community!

Recommended Posts
Change Web Worker Permissions after the Worker StartedHello, I was wondering if it is possible to change/update the permissions of a web worker after it Missing transpiled source codeI'm trying to generate coverage for my project and I'm getting the following: ``` deno task coverageTrouble validating a requestHi there! I'm trying to validate a Discord HTTP request, but I don't know how to do it (https://discHow to deploy to Deno Deploy from a Github repository's subdirectory?I read somewhere that you can deploy from a subdirectory, but I can't find any documentation on how Convert to exeI have made my Javascript program into an exe with deno: https://docs.deno.com/runtime/manual/tools/Manual deployment promotion + long lived preview deploymentsHello! I am working on a deployment pipeline and have a few questions: 1. Is there a way to promoteIs there a way to get deno coverage information in a vscode lens?If I run my tests with coverage enabled, can I get some visual feedback in vscode?Performance QuestionI have a Deno application, which creates API endpoint, and uses mongodb. Now I want to host this on Is there a way to get a server's SSL certificate's public information with Deno?This is available in Node with `getPeerCertificate()` but not in Deno's Node compatibility layer - iInvalidData: No certificates found in cert fileHello! Following up from a previous help post here, https://discord.com/channels/684898665143206084/Cannot use deno prompt when in windows CMDIt only works in the VSCode integrated terminal? I have added some output around the run command, buStreaming large files with fetch and FormDataHi, I'm trying to find a way to build multiplart/form-data requests in Deno that contain large filesIf I want to integrate a fully featured Deno runtime into my application, where do I start?I want to create a scripting environment for my application that will enable people to create customTrying to deploy a project on Deno Deploy with a private Github repository dependencyBy reading the docs at https://docs.deno.com/runtime/manual/basics/modules/private I found that I caHow can I make sure the code gets run on the client-side??!```tsx import { useEffect, useState } from "preact/hooks"; export default function Callback() { VSCode + Deno + Vite + TypescriptJust setup a project with `create-vite-extra` but all the starter files are full of typescript errorMemory LimitHello guys, in some situations i'am receiving one of the following error message `dd-hard-memory-limGoogle CalendarHi! I am looking for a minimal example how to access google calendar API. I already obtained credenI can't access my deno cloud github accountPlease help, by mistake I converted my personal github account to an organization account, and now IUploaded a module, need help!I uploaded my module: https://deno.land/x/vipps_mobilepay_sdk@0.0.1 But then I realised that I shoul