https://github.com/silverwind/parse-listen-string
Parse a HTTP server listen string
https://github.com/silverwind/parse-listen-string
Last synced: about 2 months ago
JSON representation
Parse a HTTP server listen string
- Host: GitHub
- URL: https://github.com/silverwind/parse-listen-string
- Owner: silverwind
- Created: 2022-03-22T10:51:54.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-13T19:09:14.000Z (about 2 years ago)
- Last Synced: 2024-04-14T09:49:00.208Z (about 2 years ago)
- Language: JavaScript
- Size: 945 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# parse-listen-string
[](https://www.npmjs.org/package/parse-listen-string) [](https://www.npmjs.org/package/parse-listen-string)
Node.js module to parse a listen string like `0.0.0.0:443`.
## Install
```bash
npm i parse-listen-string
```
## Usage
```js
import {parseListenString} from "parse-listen-string";
parseListenString("0.0.0.0:80")
//=> {host: "0.0.0.0", port: 80, proto: "http"}
parseListenString("https://[::1]:443")
//=> {host: "::1", port: 443, proto: "https"}
```
## API
### parseListenString(listenString)
* `listenString` *String* or *Number*: A listen string to parse
Returns a object or `null` if string can not be parsed. Object properties:
- `proto` *String*. Protocol, either `http` or `https`
- `host` *String*: Listen host in form of an IP address
- `port` *Number*: Listen port
- `path` *String*: Unix socket path, this is mutual exclusive with `host` and `port`
© [silverwind](https://github.com/silverwind), distributed under BSD licence