Method 1 Open the system default browser. For example, if you set firefox as the default browser, it will open firefox. Create a new js file with the following content:
var c = require('child_process');
c.exec('start http://www.baidu.com');
Then execute it! Open the specified browser, such as chrome,
var c = require('child_process')
c.exec("C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe http://sosout.com/"); // 前面是浏览器安装目录,后面是打开的链接
Method 2 Use a third-party library. It is recommended to use opn. This library has some optimizations.
node.js opens the browser
Method 1
Open the system default browser. For example, if you set firefox as the default browser, it will open firefox. Create a new js file with the following content:
Then execute it!
Open the specified browser, such as chrome,
Method 2
Use a third-party library. It is recommended to use opn. This library has some optimizations.
osx
windows
Use this library to open. In fact, it just encapsulates the commands for calling browsers in different operating systems
http://www.nightmarejs.org/
Take a look at this.