Language concepts

import.meta.url

Try the free JavaScript compiler

The current module URL in hosts that supply this field, including browser and Node ESM. It can serve as the base for resolving a relative URL, without loading that resource. Multi-file example: save each listed file separately, then run the entry file with Node.js. See the packaged fixture for the original files.

Formal Syntax & Structure

javascript syntaxjavascript
import.meta.url

Working Example

Example Snippetjavascript
// File: main.mjsconst url = new URL("./data.json", import.meta.url);console.log(import.meta.url.endsWith("/main.mjs"), url.pathname.endsWith("/data.json"));
JavaScript Reference