如何在没有任何插件的情况下正确重启 .JS 脚本的 node.js 内部进程

问题描述

在没有额外插件的情况下,在 main.js 中间隔重启 js 脚本的最佳方法是什么? 示例包含通用方法。

在 main.js 中

let action1 = require("./actions/action1.js"); 

setInterval(function() { 
try{
let restart = action1 .refresh();
} catch (error) {console.log("Fatal error: ",error,"\r");}

},1800000); 

action1.js

// lets say contains a scenario of an increment value stored in an array. 
// Refresh() method clear this array on time interval fired by main.js 

node.js 可以处理脚本运行时突然 main.js 再次调用同一个脚本的情况吗?它终止脚本并再次运行它?还是保持旧脚本运行并以新线程启动新脚本?

感谢您的时间!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)