There is a certain Node.js script prod.js that runs the dev server on a specific port.

 const { execSync } = require('child_process') process.env.NODE_ENV = 'production' const WEBPACK_PATH = 'node_modules/.bin/webpack' const WEBPACK_CONFIG_PATH = 'internals/webpack/configs/prod' execSync('yarn install --production=false') execSync('rm -rf ./build') execSync(`"${WEBPACK_PATH}" --config "${WEBPACK_CONFIG_PATH}"/webpack.prod.client.babel.js --display-error-details`) execSync(`"${WEBPACK_PATH}" --config "${WEBPACK_CONFIG_PATH}"/webpack.prod.server.babel.js --display-error-details`) execSync('node ./scripts/server/start-server.babel.js') 

Is it possible to demonize him? That he do the following

  • started with a physical restart of the machine (very necessary)
  • reacted to file changes
  • nailed the process at the specified port

I found a couple of modules: pm2 and nodemon , however, I do not see their ability to auto-start at system startup.

Also tried nodemon , however, the command

 nodemon ./prod.js 

Falls into a permanent reboot, therefore, the process can not even start

 [nodemon] restarting due to changes... [nodemon] starting `node scripts/prod.js` [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] starting `node scripts/prod.js` [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes... 

Who faced a similar task, tell me, please?

  • I am not strong in windows, I haven’t had a business with him for a long time, just from personal interest I want to ask - is the problem that you cannot add the program to autoload? And how does nodemon differ from fs.watch() ? - Beast Winterwolf
  • After all, there seems to be a system startup folder. Option to put there label does not fit? - Beast Winterwolf
  • Forgive me if I misunderstood something or read it inattentively. - Beast Winterwolf
  • @BeastWinterwolf Nodov scripts really can it? - while1pass
  • Startup is not the best option, because until you log into the system it will not start. - pnp2000

1 answer 1

You can use node-windows , there is an opportunity to do native windows services.

  • Yes, I'm working with this package now, thanks for the comment - while1pass
  • If it becomes invalid, either the node-windows project is closed, or the github is closed, the creation of the service under Node.js is still the same process, there is no short answer here, because apart from installing the service itself into the system, for correct operation, you need to adjust its answers to the system Event Log Windows - pnp2000
  • @ while1pass for this purpose is the most normal variant under Node, at least when I was looking for it like this - pnp2000
  • @ vnn198 I hope everything goes and I can post an extended answer. it looks simple in appearance - create a wrapper and go ahead, did not even think about logging. there is a question, we just create a script of their documentation and run it node my-service.js ? - while1pass
  • From what I read then, for the normal functioning of the script it should work with Event Logging, otherwise there may be problems, in general, everything is simple, just too much code to answer within stackoverflow - pnp2000