coreybutler / node-windows

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

node-windows with babel and pkg #346

Closed docclikdev closed 1 year ago

docclikdev commented 1 year ago

I am using babel to build and pkg to create a .exe and compressing with Brotli. The windows machine I am running the exe on does not have node installed, but pkg takes care of that. My script looks like the following: "pkg ./dist/windowsService.js --target node18-win-x64 -o abeldent-middleware.exe --compress Brotli"

and windowsService.js looks like the following:

import { Service } from 'node-windows'

// Create a new service object
const svc = new Service({
  name: 'ServiceName',
  description: 'Service description',
  script: 'server.js',
  nodeOptions: [
    '--harmony',
    '--max_old_space_size=4096'
  ]
})

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install', () => {
  svc.start()
})

svc.install()

I know it is recommended to have a global installation, but is there any way of using it packaged within? The goal is to just run the .exe file and have it run as a service.

coreybutler commented 1 year ago

It is possible to set the path of the node executable. However; pkg embeds code into the binary and won't run the way node.exe would on it's own.

The main purpose of this library is to re-use node.exe across multiple processes and/or the ability to upgrade node.exe without changing any of the app code. It is not designed to be standalone.

You may be able to set the path to the node executable by referencing pkg, but I don't know how to do that and it's not in the scope of this project.