Skip to content

Commit c64fc8d

Browse files
authored
Merge pull request #154 from Electroid/patch-1
docs: clean up readme
2 parents 64b49a5 + e49a380 commit c64fc8d

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

README.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
1-
# node-portfinder [![CI](https://github.com/http-party/node-portfinder/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/http-party/node-portfinder/actions/workflows/ci.yml)
1+
# node-portfinder
2+
3+
[![CI](https://github.com/http-party/node-portfinder/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/http-party/node-portfinder/actions/workflows/ci.yml)
24

35
## Installation
46

7+
You can install `portfinder` using a package manager like npm, yarn, or bun:
8+
59
``` bash
6-
$ npm install portfinder
10+
npm install portfinder
711
```
812

913
## Usage
1014
The `portfinder` module has a simple interface:
1115

1216
``` js
13-
var portfinder = require('portfinder');
17+
const portfinder = require('portfinder');
18+
19+
portfinder.getPort(function (err, port) {
20+
//
21+
// `port` is guaranteed to be a free port
22+
// in this scope.
23+
//
24+
});
25+
```
26+
27+
Or with promise (if `Promise`s are supported) :
28+
29+
``` js
30+
const portfinder = require('portfinder');
1431

15-
portfinder.getPort(function (err, port) {
32+
portfinder.getPortPromise()
33+
.then((port) => {
1634
//
1735
// `port` is guaranteed to be a free port
1836
// in this scope.
1937
//
38+
})
39+
.catch((err) => {
40+
//
41+
// Could not get a free port, `err` contains the reason.
42+
//
2043
});
2144
```
2245

23-
Or with promise (if `Promise`s are supported) :
24-
25-
``` js
26-
const portfinder = require('portfinder');
27-
28-
portfinder.getPortPromise()
29-
.then((port) => {
30-
//
31-
// `port` is guaranteed to be a free port
32-
// in this scope.
33-
//
34-
})
35-
.catch((err) => {
36-
//
37-
// Could not get a free port, `err` contains the reason.
38-
//
39-
});
40-
```
41-
4246
If `portfinder.getPortPromise()` is called on a Node version without Promise (<4), it will throw an Error unless [Bluebird](http://bluebirdjs.com/docs/getting-started.html) or any Promise pollyfill is used.
4347

4448
### Ports search scope
@@ -56,14 +60,14 @@ or by passing optional options object on each invocation:
5660

5761
```js
5862
portfinder.getPort({
59-
port: 3000, // minimum port
60-
stopPort: 3333 // maximum port
63+
port: 3000, // minimum port
64+
stopPort: 3333 // maximum port
6165
}, callback);
6266
```
6367

6468
## Run Tests
6569
``` bash
66-
$ npm test
70+
npm test
6771
```
6872

6973
#### Author: [Charlie Robbins][0]

0 commit comments

Comments
 (0)