DenoDDeno
Powered by
jradxlJ
Deno•2y ago•
10 replies
jradxl

Deno import use for local files?

I'm using Deno (v2) as an alternative to Bash Scripting, and I'm looking for an equivalent to Bash's Source statement, to include any common functions I might write.
Of course,
import { something } from "./myfunctions,ts"
works fine as a relative path, And an absolute path works too,
import { something } from "/home/john/.deno/mylibraries/myfunctions.ts".
But this hard codes my username in the path.

I have found that dynamic imports can be used to avoid this ,

const myhome = Deno.env.get("HOME")
const libpath = myhome + "/.deno/mylibraries/myfunctions.ts";
const myfunctions = await import(libpath);

I also thought that a webserver might work,
import { something } from "http://localhost/myfunctions.ts";
and it nearly does, shown by the intelisense in vscode, but running gives the error,
Expected a JavaScript or TypeScript module, but identified a Unknown module

Are their any other/better ways of importing modules?
I don't want to make my files public so don't want to use Github
Perhaps I could self-host Gitea
But all seem overly complex compared to Bash's Source command.

Suggestions, please?
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Globally import files for Deno subcommands
webbowerWwebbower / help
3y ago
Is deno's cache philosophy coherent for local files ?
RedBeanRRedBean / help
2y ago
jupyter / deno local import will not update
StoplionSStoplion / help
17mo ago