Skip to content
/ opn Public
forked from sindresorhus/open

A better node-open. Opens stuff like websites, files, executables. Cross-platform.

License

Notifications You must be signed in to change notification settings

chorks/opn

 
 

Repository files navigation

opn

A better node-open. Opens stuff like websites, files, executables. Cross-platform.

Why?

  • Actively maintained
  • Includes the latest xdg-open script
  • Fixes most of the node-open issues

Install

$ npm install --save opn

Usage

var opn = require('opn');

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

opn('https://sindresorhus.com', 'firefox');
// you can also specify the app to open in

opn('https://sindresorhus.com', ['google-chrome', '--incognito']);
// you can also specify the arguments of app

opn('unicorn.png');
// opens the image in the default image viewer

API

Uses the command open on OS X, start on Windows and xdg-open on other platforms.

opn(target, [app, callback])

target

Required Type: string

The thing you want to open. Can be a url, file, or executable.

Opens in the default app for the file type. Eg. urls opens in your default browser.

app

Type: string, array

Specify the app to open the target with. Where if is array, first will be app name, other will be app arguments

The app name is platform dependent. Don't hard code it in reusable modules.

callback(err)

Type: function

Executes when the opened app exits.

On Windows you have to explicitly specify an app for it to be able to wait.

CLI

You can also use it as a CLI app by installing it globally:

$ npm install --global opn
$ opn --help

Usage
  $ opn <file|url> [app] [app arguments]

Example
  $ opn https://sindresorhus.com
  $ opn https://sindresorhus.com firefox
  $ opn https://sindresorhus.com google-chrome --incognito
  $ opn unicorn.png

License

MIT © Sindre Sorhus

About

A better node-open. Opens stuff like websites, files, executables. Cross-platform.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 81.9%
  • JavaScript 18.1%