trigger node js file

后端 未结 2 1107
北恋
北恋 2020-12-17 16:33

I have a JS file that runs via node.js, so normally I crank open a terminal window and type something like node myfile.js and it runs and runs all day; fun.

2条回答
  •  被撕碎了的回忆
    2020-12-17 16:58

    I would avoid any direct interaction with the shell. It would probably be the safest, to solve it this way:

    • implement some overall "service"-script, that launches the user-node-app and keeps it running (something like https://github.com/isaacs/node-supervisor)
    • Make it, so it automatically reboots on changes of either the relevant files or a database-entry
    • With the user triggering a reboot, add a flag (timestamp?) to the database-entry or file that is watched by the reboot-script. It then will reboot the node.js-app/script.

提交回复
热议问题