node-windows icon indicating copy to clipboard operation
node-windows copied to clipboard

Change daemon directory

Open hosseinpro opened this issue 5 years ago • 6 comments

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: "./",
});

hosseinpro avatar Aug 13 '20 15:08 hosseinpro

I really need this option too!

Aoiujz avatar Sep 08 '20 02:09 Aoiujz

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

DevRCRun avatar Sep 08 '20 08:09 DevRCRun

This would be very useful!

jhong-mw avatar May 03 '21 15:05 jhong-mw

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

can-acar avatar Oct 13 '22 12:10 can-acar

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?

mdodge-ecgrow avatar May 31 '23 03:05 mdodge-ecgrow

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,
});

korzo avatar Mar 18 '24 14:03 korzo