| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/import.meta | [Back] [Original] |
Get to know MDN better
import.meta
import.meta null
import.meta import meta import
import.meta JavaScript eval() import.meta
import window.location Node.js process.env HTML
<script type="module">
import "./index.mjs?someURLInfo=5";
</script>
index.mjs import.meta someURLInfo
// index.mjs
new URL(import.meta.url).searchParams.get("someURLInfo"); // 5
// index.mjs
import "./index2.mjs?someURLInfo=5";
// index2.mjs
new URL(import.meta.url).searchParams.get("someURLInfo"); // 5
Node.js ES node index.mjs?someURLInfo=5 CommonJS URL precess.argv node index.mjs --someURLInfo=5
Node.js CommonJS __dirname ES import.meta import.meta.url URL
CommonJS
const fs = require("fs/promises");
const path = require("path");
const filePath = path.join(__dirname, "someFile.txt");
fs.readFile(filePath, "utf8").then(console.log);
ES
import fs from "node:fs/promises";
const fileURL = new URL("./someFile.txt", import.meta.url);
fs.readFile(fileURL, "utf8").then(console.log);
| ECMAScript 2027 LanguageSpecification # prod-ImportMeta |
| Web Proxy Viewer | New URL | Original Page |