node.js打开浏览器
通过nodejs的child_process
识别环境, 用不同的CLI打开默认浏览器:
var child_process = require("child_process");
var url = "http://127.0.0.1",
port=8080,
cmd = '';
switch (process.platform) {
case 'wind32':
cmd = 'start';
break;
case 'linux':
cmd = 'xdg-open';
break;
case 'darwin':
cmd = 'open';
break;
}
child_process.exec(cmd + ' ' + url + ':' + port);