Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript using `__dirname` to reference local file

My file structure looks as follows:

root
  src
    test.ts
    template.xlsx
  dist
    // compiled js source ...

In test.ts, I try to reference the spreadsheet template as follows:

path.join(__dirname, "template.xlsx");

But it is searching in path/to/root/dist instead of looking in path/to/root/src. What's the best way to access my file?

like image 885
lor Avatar asked Jan 24 '26 12:01

lor


1 Answers

If you want to access to /src from /dist you could navigate there like this:

path.join(__dirname + "../src", "template.xlsx");
like image 164
virgiliogm Avatar answered Jan 26 '26 04:01

virgiliogm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!