coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.81k stars 356 forks source link

WorkingDirectory Fix #225

Closed JoseIgnacio92 closed 4 years ago

JoseIgnacio92 commented 5 years ago

Hello!

I found an error that does not allow to correctly pass the workingDirectory parameter. I was able to solve the problem by editing the file daemon.js line 415

image

Regards!

xxsoadxx commented 5 years ago

Same issue, Great Fix!!

dustingraham commented 5 years ago

I didn't want to alter the vendor file because I was running npm install/npm ci on multiple locations with package-lock.json

I figured out a way to work around this.

const svc = new Service({...});
// Explicitly set the path for the daemon to live.
svc._directory = require('path').join(__dirname, '..');
svc.install();

Have not done very intensive testing, but at first glance this seems to put the daemon in the parent directory relative to where the install script is called from. You could certainly pass an absolute path as well.

Edit: So, this works to move the /daemon/ folder away, which is great! However, I also wanted to use a windows junction to hot-swap the target folder. Hitting a snag since the wrapper parameter in daemon is generated at service installation time, and uses the path to the wrapper.js file, which includes the actual folder, rather than the windows junction folder. So removing the old folder after swapping causes the service to fail. I'm probably an extreme edge case, and the above does work for moving the daemon folder out of the folder where the script lives.

DanielRuf commented 4 years ago

You can use patch-package to apply changes.

coreybutler commented 4 years ago

I added this to master. It will go out in the 1.0.0 release.