0

So I have written a short node module (module1) as a wrapper for a binary (.exe) that can be called via command line.

This is how I get the path to the binary to execute the .exe with execFilePromised. It works in my module1.

const __dirname = fs.realpathSync('.');
const mpqEditorLocation = path.resolve(__dirname, './mpq/MPQEditor.exe');

Problem: When I import module1 with npm link ../<module1> into another node project the path is not correctly set to the .exe since this resides in my node_modules folder and not at <otherproject>/mpq/MPQEditor.exe

How can I make the __dirname relative to the actual file not the project execution directory?

rufreakde
  • 542
  • 4
  • 17

1 Answers1

0

So I found my solution do not use npm link!

Use npm install <absolute path to your package> instead.

I just printed my location with pwdand then installed it there.

That way I could refactor the pathing to:

const mpqEditorLocation = path.resolve(__dirname, '..', 'mpq', 'MPQEditor.exe');

worked since then :)

rufreakde
  • 542
  • 4
  • 17