How would you launch a browser from the a node.js command line script


Question

Possible Duplicate:
How to use nodejs to open default browser and navigate to a specific URL

I don't know if it matters, but I am on OSX.

I know you can launch a browser from the command line itself by typing:

open http://www.stackoverflow.com

But is there a way to open a browser from inside a nodejs command line script?

1
47
5/23/2017 12:34:42 PM

Use opn because it will handle the cross platform issue. To install:

$ npm install opn

To use:

var opn = require('opn');

// opens the url in the default browser 
opn('http://sindresorhus.com');

// specify the app to open in 
opn('http://sindresorhus.com', {app: 'firefox'});
145
1/26/2017 2:08:06 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon