Using the node-windows package, I am installing a node server locally as a service. Having then an interface to modify the .env file, when I actually modify the configurations of the .env and save the changes, the issue is that the service does not restart as it is supposed to, in order to acknowledge these changes. Can anyone guide me if there any other way to handle service restarts from this package, or any other workarounds similiar? I actually am trying to handle the restart like this:
const path = require("path");
let Service = require("node-windows").Service;
let EventLogger = require("node-windows").EventLogger;
const Messages= require("./models/messagesModel").getInstance();
let filePathServer = path.resolve(__dirname, "app.backend.js");
class ServiceInstall {
constructor(envConfig) {
this.log = new EventLogger(envConfig.SERVICE_NAME);
this.svc = new Service({
name: envConfig.SERVICE_NAME,
description: envConfig.SERVICE_DESCRIPTION,
script: filePathServer,
wait: envConfig.SERVICE_WAIT,
grow: envConfig.SERVICE_GROW
});
}
installWindowsService() {
// event handlers to install the service
}
restartWindowsService(){
this.svc.on("stop", () => {
this.log.info("Service " + this.svc.name + " stopped!");
Messages.info("Service " + this.svc.name + " stopped!");
});
this.svc.on("start", () => {
this.log.info("Service " + this.svc.name + " started!");
Messages.info("Service " + this.svc.name + " started!");
});
this.svc.restart();
}
}
module.exports = ServiceInstall;