• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# It Opens Stuff
2
3That is, in your desktop environment. This will make *actual windows pop up*, with stuff in them:
4
5```bash
6npm install opener -g
7
8opener http://google.com
9opener ./my-file.txt
10opener firefox
11opener npm run lint
12```
13
14Also if you want to use it programmatically you can do that too:
15
16```js
17var opener = require("opener");
18
19opener("http://google.com");
20opener("./my-file.txt");
21opener("firefox");
22opener("npm run lint");
23```
24
25Plus, it returns the child process created, so you can do things like let your script exit while the window stays open:
26
27```js
28var editor = opener("documentation.odt");
29editor.unref();
30// These other unrefs may be necessary if your OS's opener process
31// exits before the process it started is complete.
32editor.stdin.unref();
33editor.stdout.unref();
34editor.stderr.unref();
35```
36
37## Use It for Good
38
39Like opening the user's browser with a test harness in your package's test script:
40
41```json
42{
43    "scripts": {
44        "test": "opener ./test/runner.html"
45    },
46    "devDependencies": {
47        "opener": "*"
48    }
49}
50```
51
52## Why
53
54Because Windows has `start`, Macs have `open`, and *nix has `xdg-open`. At least [according to some person on StackOverflow](http://stackoverflow.com/q/1480971/3191). And I like things that work on all three. Like Node.js. And Opener.
55