Skip to content

filePathsFromImportMeta

Prefer import.meta.dirname and import.meta.filename over legacy file path techniques.

✅ This rule is included in the node stylistic and stylisticStrict presets.

Node.js 20.11 introduced import.meta.dirname and import.meta.filename as modern alternatives to legacy file path techniques. These properties provide direct access to directory and file paths without requiring imports from node:path or node:url.

  • import.meta.filename is equivalent to fileURLToPath(import.meta.url).
  • import.meta.dirname is equivalent to path.dirname(fileURLToPath(import.meta.url)) and similar legacy patterns.
AEconsB0filenaAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0fileURLToPa5<3(sp ansty="le--0:#C792EA;--1:#8844">AEimpor72meA72u53<);d ivclassNa="meco"><);d>AEconsB0dirnaAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53paAB0dirna5<3(sp ansty="le--0:#82AAFF;--1:#3B61">B0fileURLToPa5<3(sp ansty="le--0:#C792EA;--1:#8844">AEimpor72meA72u53)<);d ivclassNa="meco"><);d>AEconsB0dirnaAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53paAB0dirna5<3(sp ansty="le--0:#C792EA;--1:#8844">AEimpor72meA72filena53<);d ivclassNa="meco"><);d>AEconsB0uAE <= sp ansty="le--0:#82AAFF;--1:#3B61">B0fileURLToPa5<3(sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0U5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">41<1"sp ansty="le--0:#C792EA;--1:#8844">AE, impor72meA72u53)<);d ivclassNa="meco"><);d>
44AEco61B0file44AE = imp6E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72file3<;di vdivclass="Nameexpressive-">44AEco61B0dir44AE = imp6E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72dir3<;di vdivclass="Nameexpressive-">44AEco61B<0url spans="tyle--0:#C792EA;--1:#88">44AE = imp6E724<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E7<2url spans="tyle--0:#D6DEEB;--1:#40">3

This rule is not configurable.

If you need to support Node.js versions earlier than 20.11, you should not enable this rule. Stylistically, if you prefer dynamically constructing URLs to be consistent, this rule might not be for you.