Skip to content

Instantly share code, notes, and snippets.

@blackdzcuto
Created June 27, 2024 12:05
Show Gist options
  • Save blackdzcuto/fd4a5677d67fbb17a68e86d367a99399 to your computer and use it in GitHub Desktop.
Save blackdzcuto/fd4a5677d67fbb17a68e86d367a99399 to your computer and use it in GitHub Desktop.
const { spawn } = require("child_process");
function run(script) {
const child = spawn(
"node",
[
"--trace-deprecation",
script
],
{
cwd: __dirname,
stdio: "inherit",
shell: true,
}
);
child.on("close", (codeExit) => {
if (codeExit !== 0) {
console.log(`[ RESTART ] Đang khởi động lại ${script}...`);
run(script);
} else {
console.log(`[ STOP ] Tiến trình con ${script} đã kết thúc!`);
}
});
child.on("error", function (error) {
console.error(`[ ERROR ] Đã xảy ra lỗi với ${script}: ` + JSON.stringify(error));
});
}
run("main.js");
//run("like.js");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment