Ask node how to automatically open the browser and open the specified web address.

  node.js, question

Ask node how to automatically open the browser and open the specified web address.

Js opens browser.

  • Method one
    Open the system default browser. For example, if you set firfox as the default browser, it will open firefox. Create a new js file with the following contents:

var c = require('child_process');
 c.exec('start http://www.baidu.com');

Then execute it!
Open a specific browser, such as chrome.

var c = require('child_process')
 c.exec("C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe http://sosout.com/");  //The browser installation directory is in front, followed by an open link.
  • Method 2
    Using the third-party library, it is recommended to useopnThis library has been optimized.