Categories
JavaScript Answers

How to install Node.js as windows service?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *