I am working on a node.js project where I have to define different endpoints to open and close browsers on specific endpoints.
Like on: localhost:3000/open---> opens the browser
localhost:3000/close---> closes the browser
I have made child process that opens the browser and kills it but how to integrate it with a express api,Any idea?
Here's my code:
var start = (process.platform == 'darwin'? 'open': process.platform == 'win32'? 'start': 'xdg-open');
//open browser
var url = 'https://www.google.com';
var cmd = start + ' ' + url;
var child = require('child_process').exec(cmd, function(error, stdout, stderr) {
if (error) {
console.log('exec error: ' + error);
}
});
//close browser
process.on('SIGINT', function() {
child.kill();
process.exit();
});