coreybutler / node-windows

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

Change daemon directory #269

Open hosseinpro opened 4 years ago

hosseinpro commented 4 years ago

I put my source files in /src similar to many other projects and since my index.js in under /src the output daemon folder will be created as /src/daemon. I need to specify the output daemon folder in node-windows config like daemonDir. If you add this option it's very good.

Meanwhile, I solved my problem as follows:

I changed node_modules\node-windows\lib\daemon.js file at line 258 from:

_directory: {
      enumerable: false,
      writable: true,
      configurable: false,
      value: config.script !== null ? path.dirname(config.script) : null
    },

to

_directory: {
      enumerable: false,
      writable: true,
      configurable: false,
      value: config.daemonDir !== null ? path.dirname(config.daemonDir) : null
    },

And specify daemonDir at config:

var svc = new Service({
  name: "My Server",
  description: "My Server",
  script: "src/index.js",
  daemonDir: "./",
});
Aoiujz commented 4 years ago

I really need this option too!

DevRCRun commented 4 years ago

I'll be looking at this today too, as I ideally want the scripts and their daemon directories away from the project

jhong-mw commented 3 years ago

This would be very useful!

can-acar commented 2 years ago

I added custom property 'installPath':'./daemon' my repo: https://github.com/can-acar/Node-Windows

mdodge-ecgrow commented 1 year ago

I wanted to install a second Node service from the same base folder. I followed @hosseinpro 's instructions to create the daemon in an alternate folder. I had this line in my install file: daemonDir: './daemon-process-queue', but for some reason it still installed to the same daemon folder as the other service. Now I have both in there with different names. I was able to start both services under services.msc. Now I am wondering if this will cause any future problems or not?

korzo commented 8 months ago

While this is fixed, you can replace the _directory property

const service = new Service({
  name: 'My Service',
  script: join(__dirname, '..', 'main.js'),
});

const installDir = join(__dirname, '..', '..');

Object.defineProperty(service, '_directory', {
  enumerable: false,
  writable: true,
  configurable: false,
  value: installDir,
});