Quick Tip: Node.js Open URL in User’s Preferred Application/Browser

Using the node-open module you can open files or URLs in the user’s preferred application.

For example this piece code will open CSSDeck in the user’s default browser (for me it’s Google Chrome) –

[js]
var open = require(‘open’);
open(‘http://cssdeck.com’);
[/js]

You can also open mailto URLs in the browser or the email client (depending upon user’s preferences) –

[js]
var open = require(‘open’);
open(‘mailto:your_email@gmail.com’);
[/js]

The module handles cross-platform issues pretty well!

Author: Rishabh

Rishabh is a full stack web and mobile developer from India. Follow me on Twitter.