To install Node.js as windows service, we use the node-windows
package.
For instance, we write
const Service = require("node-windows").Service;
const svc = new Service({
name: "Hello World",
description: "The nodejs.org example web server.",
script: "C:\\path\\to\\helloworld.js",
});
svc.on("install", () => {
svc.start();
});
svc.install();
to create a Service
object with the name
, description
and the program location.
Then we listen for the install
event with on
and call start
to start the service once it’s installed.
Finally, we call install
to install the service.