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

277
Views
NodeJS: How to get a path a module was imported from

I have a module with some exported function that creates a file.

fs.appendFile(`${__dirname}/file_name`, 'aaaa', () => {});

When I import this module using a require syntax, when calling the function, the file is created in .node_modules/my_module/ (probably as expected). The question is how can I make it to create a file in the folder I'm calling this function.

I don't have an option to inject the path when calling the function, in the real app it's called by a third party reflection mechanism.

about 4 years ago · Juan Pablo Isaza
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!