10000 GitHub - Louis-Tian/listhen: Elegant HTTP Listener ๐Ÿ‘‚
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Louis-Tian/listhen

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

57 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

listhen

๐Ÿ‘‚ listhen

Elegant http listener

npm version npm downloads Github Actions Codecov

โœ”๏ธ Promisified interface for listening and closing server

โœ”๏ธ Works with express/connect or plain http handle function

โœ”๏ธ Support HTTP and HTTPS

โœ”๏ธ Automatically assign a port or fallback to human friendly alternative (with get-port-please)

โœ”๏ธ Automatically generate listening URL and show on console

โœ”๏ธ Automatically copy URL to clipboard

โœ”๏ธ Automatically open in browser (opt-in)

โœ”๏ธ Automatically generate self signed certificate

โœ”๏ธ Automatically detect test and production environments

โœ”๏ธ Automatically close on exit signal

โœ”๏ธ Gracefully shutdown server with http-shutdown

Install

Install using npm or yarn:

npm i listhen
# or
yarn add listhen

Import into your Node.js project:

// CommonJS
const { listen } = require('listhen')

// ESM
import { listen } from 'listhen'

Usage

Function signature:

const { url, getURL, server, close } = await listen(handle, options?)

Plain handle function:

listen('/', ((_req, res) => {
  res.end('hi')
})

With express/connect:

const express = require('express')
const app = express()

app.use('/', ((_req, res) => {
  res.end('hi')
})

listen(app)

Options

port

  • Default: process.env.PORT or 3000 or memorized random (see get-port-please)

Port to listen.

https

  • Default: false

Listen with https protocol. By default uses a self-signed certificated.

certificate

Path to https certificate files { key, cert }

selfsigned

Options for self-signed certificate (see selfsigned).

showURL

  • Default: true (force disabled on test environment)

Show a CLI message for listening URL.

baseURL

  • Default: /

open

  • Default: false (force disabled on test and production environments)

Open URL in browser. Silently ignores errors.

clipboard

  • Default: false (force disabled on test and production environments)

Copy URL to clipboard. Silently ignores errors.

isTest

  • Default: process.env.NODE_ENV === 'test'

Detect if running in a test environment to disable some features.

autoClose

  • Default: true

Automatically close when an exit signal is received on process.

License

MIT. Made with ๐Ÿ’–

About

Elegant HTTP Listener ๐Ÿ‘‚

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%
0