# find-free-port-sync

> Find free port synchronously without callback

Latest version **1.0.0** (published 2018-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install find-free-port-sync
pnpm add find-free-port-sync
yarn add find-free-port-sync
bun add find-free-port-sync
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-06-16 |
| First published | 2018-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | imwtr |
| Maintainers | imwtr |
| Keywords | post-scanner, free-port, synchronous, webpack-dev-server |

## Links

- npm: https://www.npmjs.com/package/find-free-port-sync
- Repository: https://github.com/imwtr/find-free-port-sync
- Homepage: https://github.com/imwtr/find-free-port-sync#readme
- Issues: https://github.com/imwtr/find-free-port-sync/issues
- npm.io page: https://npm.io/package/find-free-port-sync

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-06-16

## README

# Description
Find free port synchronously, useful when you need to get the port directly without callback.

Like config [webpack-dev-server](https://github.com/webpack/webpack-dev-server) with port automatically.

```javascript
module.exports = {
    ...
    output: '...',
    devServer: {
        ...
        port: "a free port"
    }
};
```

# Installation
```javascript
npm install find-free-port-sync --save-dev
```

# Options

## start
`type: number | default: 1`

Start of range to find, should be greater than 0

## end
`type: number | default: 65534`

End of range to find, should be less than 65535

## num
`type: number | default: 1`

Number of ports to find, relates to the return value
- When `num === 1`, return a free random `port` if found, `null` if not
- When `num > 1`, return an array of free `[port]` orderly if found, empty array `[]` if not

## ip
`type: string | default: 0.0.0.0|127.0.0.1`

It will scan local adress by default, specify an ip here

## port
`type: number | default: null`

If port is defined, it will return whether the port is free around `start` `end` `ip` option


## Examples
Find a free port for local address
```javascript
let findFreePort = require('find-free-port-sync');

let port = findFreePort();
```
Find 10 free ports between 10000 and 30000 for 192.168.1.1
```javascript
let findFreePort = require('find-free-port-sync');

let port = findFreePort({
    start: 10000,
    end: 30000,
    num: 10,
    ip: '192.168.1.1'
});
```
Check if a port is free
```javascript
let findFreePort = require('find-free-port-sync');

let portIsOk = findFreePort({
    port: 12345
});
```

---
_Source: https://npm.io/package/find-free-port-sync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
