Last active
January 12, 2021 14:03
-
-
Save kaansoral/9b7a20c15e0fb002959804ae6fcaa7d6 to your computer and use it in GitHub Desktop.
Auto Re-Run AppEngine NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var child_process=require('child_process'),fs=require('fs'); | |
var dir="/Users/kaan/project"; | |
process.env.GOOGLE_CLOUD_PROJECT="project-dev"; | |
process.env.GOOGLE_APPLICATION_CREDENTIALS=dir+"/utility/service_account.json"; | |
var node_sdk=null; | |
function rerun_node_sdk() | |
{ | |
if(node_sdk) node_sdk.kill(); | |
node_sdk=child_process.spawn("node",[dir+"/main.js"],{cwd:dir,env:process.env,stdio: "inherit"}); | |
node_sdk.on('spawn',()=>{ | |
console.log("\x1b[35m[AUTORUN]\x1b[0m spawned the process"); | |
}); | |
node_sdk.on('error',(err)=>{ | |
console.error("\x1b[35m[AUTORUN]\x1b[0m Failed to spawn the process: "+err); | |
}); | |
node_sdk.on('close',(code)=>{ | |
console.log("\x1b[35m[AUTORUN]\x1b[0m process exited with code"+code); | |
}); | |
} | |
rerun_node_sdk(); | |
watcher1=fs.watch(dir,{recursive:true},function(event,fname){ | |
rerun_node_sdk(); | |
}); | |
process.stdin.on('data',function(chunk){ | |
if(chunk.indexOf("\n")!=-1) | |
rerun_node_sdk(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment