You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

3 months ago
  1. # It Opens Stuff
  2. That is, in your desktop environment. This will make *actual windows pop up*, with stuff in them:
  3. ```bash
  4. npm install opener -g
  5. opener http://google.com
  6. opener ./my-file.txt
  7. opener firefox
  8. opener npm run lint
  9. ```
  10. Also if you want to use it programmatically you can do that too:
  11. ```js
  12. var opener = require("opener");
  13. opener("http://google.com");
  14. opener("./my-file.txt");
  15. opener("firefox");
  16. opener("npm run lint");
  17. ```
  18. Plus, it returns the child process created, so you can do things like let your script exit while the window stays open:
  19. ```js
  20. var editor = opener("documentation.odt");
  21. editor.unref();
  22. // These other unrefs may be necessary if your OS's opener process
  23. // exits before the process it started is complete.
  24. editor.stdin.unref();
  25. editor.stdout.unref();
  26. editor.stderr.unref();
  27. ```
  28. ## Use It for Good
  29. Like opening the user's browser with a test harness in your package's test script:
  30. ```json
  31. {
  32. "scripts": {
  33. "test": "opener ./test/runner.html"
  34. },
  35. "devDependencies": {
  36. "opener": "*"
  37. }
  38. }
  39. ```
  40. ## Why
  41. Because 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.