web 3d图形渲染器
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.

108 lines
2.1 KiB

  1. [![logo][logo-image]][logo-url]
  2. ---
  3. [![NPM version][npm-image]][npm-url]
  4. [![build status][travis-image]][travis-url]
  5. [![Test coverage][codecov-image]][codecov-url]
  6. [![npm download][download-image]][download-url]
  7. [logo-image]: ./logo.png
  8. [logo-url]: https://npmjs.org/package/detect-port
  9. [npm-image]: https://img.shields.io/npm/v/detect-port.svg?style=flat-square
  10. [npm-url]: https://npmjs.org/package/detect-port
  11. [travis-image]: https://img.shields.io/travis/node-modules/detect-port.svg?style=flat-square
  12. [travis-url]: https://travis-ci.org/node-modules/detect-port
  13. [codecov-image]: https://codecov.io/gh/node-modules/detect-port/branch/master/graph/badge.svg
  14. [codecov-url]: https://codecov.io/gh/node-modules/detect-port
  15. [download-image]: https://img.shields.io/npm/dm/detect-port.svg?style=flat-square
  16. [download-url]: https://npmjs.org/package/detect-port
  17. > JavaScript Implementation of Port Detector
  18. ## Usage
  19. ```bash
  20. $ npm i detect-port --save
  21. ```
  22. ```js
  23. const detect = require('detect-port');
  24. /**
  25. * callback usage
  26. */
  27. detect(port, (err, _port) => {
  28. if (err) {
  29. console.log(err);
  30. }
  31. if (port == _port) {
  32. console.log(`port: ${port} was not occupied`);
  33. } else {
  34. console.log(`port: ${port} was occupied, try port: ${_port}`);
  35. }
  36. });
  37. /**
  38. * for a yield syntax instead of callback function implement
  39. */
  40. const co = require('co');
  41. co(function *() {
  42. const _port = yield detect(port);
  43. if (port == _port) {
  44. console.log(`port: ${port} was not occupied`);
  45. } else {
  46. console.log(`port: ${port} was occupied, try port: ${_port}`);
  47. }
  48. });
  49. /**
  50. * use as a promise
  51. */
  52. detect(port)
  53. .then(_port => {
  54. if (port == _port) {
  55. console.log(`port: ${port} was not occupied`);
  56. } else {
  57. console.log(`port: ${port} was occupied, try port: ${_port}`);
  58. }
  59. })
  60. .catch(err => {
  61. console.log(err);
  62. });
  63. ```
  64. ## Command Line Tool
  65. ```shell
  66. $ npm i detect-port -g
  67. ```
  68. ### Quick Start
  69. ```shell
  70. # get an available port randomly
  71. $ detect
  72. # detect pointed port
  73. $ detect 80
  74. # more help
  75. $ detect --help
  76. ```
  77. ## Authors
  78. - [xudafeng](//github.com/xudafeng)
  79. - [zenzhu](//github.com/zenzhu)
  80. ## License
  81. [MIT](LICENSE)