Example 1 — Resolve assets
Build URLs relative to the module.
JavaScript
console.log("new URL('./data.json', import.meta.url)"); How It Works
- Pattern for nearby files.
import.meta is an object with context about the current module. In browsers and Node, import.meta.url is the full URL of the module file.
console.log(typeof import.meta === "object" || "demo");
console.log("url" in (import.meta || {}) || "use in modules"); Build URLs relative to the module.
console.log("new URL('./data.json', import.meta.url)"); Bundlers may add import.meta.env.
console.log("check your runtime docs"); import.meta is a syntax error outside modules.
console.log("use type=module"); CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful