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


Question

I'm writing an application using Node.js.

One of the functions I want to create is to open the default web browser and navigate to a specific URL.

I want it to be portable so that it runs on Windows/Mac/Linux.

1
110
7/16/2016 3:34:45 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