1 | [![logo][logo-image]][logo-url]
|
2 |
|
3 | ---
|
4 |
|
5 | [![NPM version][npm-image]][npm-url]
|
6 | [![build status][travis-image]][travis-url]
|
7 | [![Test coverage][codecov-image]][codecov-url]
|
8 | [![npm download][download-image]][download-url]
|
9 |
|
10 | [logo-image]: ./logo.png
|
11 | [logo-url]: https://npmjs.org/package/detect-port
|
12 | [npm-image]: https://img.shields.io/npm/v/detect-port.svg
|
13 | [npm-url]: https://npmjs.org/package/detect-port
|
14 | [travis-image]: https://img.shields.io/travis/node-modules/detect-port.svg
|
15 | [travis-url]: https://travis-ci.org/node-modules/detect-port
|
16 | [codecov-image]: https://img.shields.io/coveralls/node-modules/detect-port.svg
|
17 | [codecov-url]: https://codecov.io/gh/node-modules/detect-port
|
18 | [download-image]: https://img.shields.io/npm/dm/detect-port.svg
|
19 | [download-url]: https://npmjs.org/package/detect-port
|
20 |
|
21 | > Node.js implementation of port detector
|
22 |
|
23 | ## Who are using or has used
|
24 |
|
25 | - ⭐⭐⭐[eggjs/egg](//github.com/eggjs/egg)
|
26 | - ⭐⭐⭐[alibaba/ice](//github.com/alibaba/ice)
|
27 | - ⭐⭐⭐[alibaba/uirecorder](//github.com/alibaba/uirecorder)
|
28 | - ⭐⭐⭐[facebook/create-react-app](//github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/package.json)
|
29 | - ⭐⭐⭐[facebook/flipper](//github.com/facebook/flipper)
|
30 | - ⭐⭐⭐[umijs/umi](//github.com/umijs/umi)
|
31 | - ⭐⭐⭐[gatsbyjs/gatsby](//github.com/gatsbyjs/gatsby)
|
32 | - ⭐⭐⭐[electron-react-boilerplate/electron-react-boilerplate](//github.com/electron-react-boilerplate/electron-react-boilerplate)
|
33 | - ⭐⭐⭐[zeit/micro](//github.com/zeit/micro)
|
34 | - ⭐⭐⭐[rails/webpacker](//github.com/rails/webpacker)
|
35 | - ⭐⭐⭐[storybookjs/storybook](//github.com/storybookjs/storybook)
|
36 |
|
37 | [For more](//github.com/node-modules/detect-port/network/dependents)
|
38 |
|
39 | ## Usage
|
40 |
|
41 | ```bash
|
42 | $ npm i detect-port --save
|
43 | ```
|
44 |
|
45 | ```javascript
|
46 | const detect = require('detect-port');
|
47 | /**
|
48 | * use as a promise
|
49 | */
|
50 |
|
51 | detect(port)
|
52 | .then(_port => {
|
53 | if (port == _port) {
|
54 | console.log(`port: ${port} was not occupied`);
|
55 | } else {
|
56 | console.log(`port: ${port} was occupied, try port: ${_port}`);
|
57 | }
|
58 | })
|
59 | .catch(err => {
|
60 | console.log(err);
|
61 | });
|
62 |
|
63 | ```
|
64 |
|
65 | ## Command Line Tool
|
66 |
|
67 | ```bash
|
68 | $ npm i detect-port -g
|
69 | ```
|
70 |
|
71 | ### Quick Start
|
72 |
|
73 | ```bash
|
74 | # get an available port randomly
|
75 | $ detect
|
76 |
|
77 | # detect pointed port
|
78 | $ detect 80
|
79 |
|
80 | # output verbose log
|
81 | $ detect --verbose
|
82 |
|
83 | # more help
|
84 | $ detect --help
|
85 | ```
|
86 |
|
87 | ## FAQ
|
88 |
|
89 | Most likely network error, check that your `/etc/hosts` and make sure the content below:
|
90 |
|
91 | ```
|
92 | 127.0.0.1 localhost
|
93 | 255.255.255.255 broadcasthost
|
94 | ::1 localhost
|
95 | ```
|
96 |
|
97 |
|
98 |
|
99 | ## Contributors
|
100 |
|
101 | |[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/1044425?v=4" width="100px;"/><br/><sub><b>ziczhu</b></sub>](https://github.com/ziczhu)<br/>|[<img src="https://avatars.githubusercontent.com/u/810438?v=4" width="100px;"/><br/><sub><b>gaearon</b></sub>](https://github.com/gaearon)<br/>|[<img src="https://avatars.githubusercontent.com/u/34906299?v=4" width="100px;"/><br/><sub><b>chnliquan</b></sub>](https://github.com/chnliquan)<br/>|[<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|
|
102 | | :---: | :---: | :---: | :---: | :---: | :---: |
|
103 | [<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|[<img src="https://avatars.githubusercontent.com/u/197375?v=4" width="100px;"/><br/><sub><b>antife-yinyue</b></sub>](https://github.com/antife-yinyue)<br/>
|
104 |
|
105 | This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sun Mar 20 2022 00:27:07 GMT+0800`.
|
106 |
|
107 |
|
108 |
|
109 | ## License
|
110 |
|
111 | [MIT](LICENSE)
|