Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Relative path with import.meta.url

When working with ESM, quite a number of recommendation to load json file using import.meta.url as below

import fs from 'fs';
const result = fs.readFileSync(
  new URL("abc.json", import.meta.url)
);

Now the above works, but with the assumption that abc.json is in same directory with the location of the script. I'm wondering what about relative path of the script such as abc.json is at one level up of directory. I tried below but it's not working

import fs from "fs";
import path from "path";

const result = fs.readFileSync(
  new URL("abc.json", path.resolve(import.meta.url, "../"))
);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Instead of applying path.resolve to import.meta.url, you should specify the relative path as the first parameter such as below

const result = fs.readFileSync(
  new URL("../abc.json", import.meta.url)
);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!