#`require()` equivalent

17 messages · Page 1 of 1 (latest)

north spruce
#

Just the usual JavaScript import

#

import myData from "./some-data.json" assert { type: "json" };

#

You won't need the assertion for js, JSX, etc tho

boreal charm
#

Thanks, it works indeed.

boreal charm
#

For example, can I import a yaml file? It looks like I cannot.

north spruce
#

and with node compatibility, you can import vue, svelte, etc

#

for yaml, you can just use Deno.readFileSync and then parse the text content

boreal charm
north spruce
#

If you still need to, you can just fetch() it as text content, right?

#

await fetch("your_file_url").then(res => res.text())

iron flicker
#

Not sure if it still works, but it used to be what you used to sidestep that problem a while ago

boreal charm
#

@iron flicker I'm sorry, I'm a noob when it comes to web development, and I don't understand the scope of the project. I want to create a webapp, and I'm not sure if Deno is the right tool for that.
After reading again the documentation, it looks like Deno is an alternative to Nodejs, so it should be used for server side. Per the Deno documentation, if I want a bundler to transpile & pack my app together, I should use esbuild, but then I'm back to the npm ecosystem, right?