listening-on

Print server url with local and network ip address

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
listening-on
002.0.92 years ago3 years agoMinified + gzip package size for listening-on in KB

Readme

listening-on
Print server url with local and network ip address
npm Package Version npm Package Version npm Package Version
Plain node.js alternative to running-at.
This package doesn't rely on execa and ip, hence more portable.

Installation

## with npm
npm i listening-on

## or with pnpm
pnpm i listening-on

## or with yarn
yarn add listening-on

Usage Example

Named import example:
import express from 'express'
import { print } from 'listening-on'

const PORT = +process.env.PORT! || 3000
const app = express()

app.use(express.static('public'))

app.listen(PORT, () => {
  print(PORT)
  /* will print out below lines:
listening on http://127.0.0.1:8100 (lo)
listening on http://192.168.59.46:8100 (wlp3s0)
    */
})

commonjs compatible import example:
import * as listeningOn from 'listening-on'

listeningOn.print(PORT)

// or simply use require
require('listening-on').print(PORT)

Typescript Signature

export function print(port_or_options: number | PrintOptions): void

export type PrintOptions = {
  port: number
  // default http
  protocol?: Protocol | string
  // default IPv4
  family?: Family | 'all'
}

export type Protocol = 'http' | 'https' | 'ws' | 'wss' | 'tcp' | 'udp'

export type Family = 'IPv4' | 'IPv6'

License

This is free and open-source software (FOSS) with BSD-2-Clause License