Installations
npm install @joshmossas/listhen
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
20.16.0
NPM Version
10.8.1
Score
64
Supply Chain
95.5
Quality
79.7
Maintenance
100
Vulnerability
98.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.53%)
JavaScript (0.47%)
Love this project? Help keep it running ā sponsor us today! š
Developer
unjs
Download Statistics
Total Downloads
4,232
Last Day
12
Last Week
31
Last Month
259
Last Year
3,274
GitHub Statistics
NOASSERTION License
487 Stars
320 Commits
32 Forks
4 Watchers
10 Branches
33 Contributors
Updated on Feb 10, 2025
Package Meta Information
Latest Version
1.11.1
Package Id
@joshmossas/listhen@1.11.1
Unpacked Size
175.16 kB
Size
45.19 kB
File Count
20
NPM Version
10.8.1
Node Version
20.16.0
Published on
Oct 04, 2024
Total Downloads
Cumulative downloads
Total Downloads
4,232
Last Day
0%
12
Compared to previous day
Last Week
-13.9%
31
Compared to previous week
Last Month
24.5%
259
Compared to previous month
Last Year
241.8%
3,274
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
š listhen
Elegant HTTP listener!
Features
ā
Dev server with HMR, static, WebSockets and TypeScript support with unjs/jiti
ā
Works with Node.js, Express, and unjs/h3 out of the box
ā
Show the QR code of the public URL with unjs/uqr
ā
Tunnel your local server to the world with unjs/untun
ā Assign a port or fallback to a nicer alternative with unjs/get-port-please
ā
Gracefully shutdown Server with http-shutdown
ā Zero Config WebSockets with unjs/crossws
ā
Copy the URL to the clipboard
ā
HTTPS support with self-signed certificates
ā
Open URL in browser
ā
Detect test and production environments to auto-adjust behavior
ā
Close on the exit signal

Quick Usage (CLI)
You can run your applications in localhost with TypeScript support and watch mode using listhen
CLI:
Create index.ts
:
1export default (req, res) => { 2 res.end("Hello World!"); 3};
or using unjs/h3:
1import { createApp, eventHandler } from "h3"; 2 3export const app = createApp(); 4 5app.use( 6 "/", 7 eventHandler(() => "Hello world!"), 8);
or use npx to invoke listhen
command:
1npx listhen -w ./index.ts
Usage (API)
Install package:
1# pnpm 2pnpm i listhen 3 4# npm 5npm i listhen 6 7# yarn 8yarn add listhen 9
Import into your Node.js project:
1// CommonJS 2const { listen, listenAndWatch } = require("listhen"); 3 4// ESM 5import { listen, listenAndWatch } from "listhen";
1const handler = (req, res) => { 2 res.end("Hi!") 3} 4 5// listener: { url, getURL, server, close, ... } 6const listener = await listen(handler, options)
Options
port
- Default:
process.env.PORT
or 3000 or memorized random (see get-port-please)
Port to listen.
hostname
- Default:
process.env.HOST || '0.0.0.0'
Default hostname to listen.
https
- Type: Boolean | Object
- Default:
false
Listen on HTTPS with SSL enabled.
Self-Signed Certificate
By setting https: true
, listhen will use an auto-generated self-signed certificate.
You can set https to an object for custom options. Possible options:
domains
: (Array) Default is['localhost', '127.0.0.1', '::1']
.validityDays
: (Number) Default is1
.
User-Provided Certificate
Set https: { cert, key }
where the cert and key are paths to the SSL certificates.
With an encrypted private key, you also need to set passphrase
on the https
object.
To provide a certificate stored in a keystore set https: { pfx }
with a path to the keystore.
When the keystore is password protected also set passphrase
.
You can also provide an inline cert and key instead of reading from the filesystem. In this case, they should start with --
.
http2
- Type: Boolean
- Default:
false
HTTP-Versions 1 and 2 will be used when enabled; otherwise only HTTP 1 is used.
showURL
- Default:
true
(force disabled on a test environment)
Show a CLI message for the listening URL.
baseURL
- Default:
/
open
- Default:
false
(force disabled on test and production environments)
Open the URL in the browser. Silently ignores errors.
clipboard
- Default:
false
(force disabled on test and production environments)
Copy the URL to the 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
event, SIGTERM
, SIGINT
or SIGHUP
signal is received in the process.
publicURL
- Default: (the first public URL listening)
The public URL to show in the CLI output
qr
- Default:
true
Print QR Code for public address.
public
- Default:
false
for development or whenhostname
islocalhost
andtrue
for production
When enabled, listhen tries to listen to all network interfaces. You can also enable this option using --host
CLI flag.
ws
- Default:
false
Enable experimental WebSocket support using unjs/crossws or node upgrade handler.
Option can be a function for Node.js upgrade
handler ((req, head) => void
) or an Object to use CrossWS Hooks.
When using dev server CLI, you can easily use --ws
and a named export called websocket
to define CrossWS Hooks with HMR support!
License
Published under the MIT license.
Made by @pi0 and community š
š¤ auto updated with automd

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
5 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-7q7g-4xm8-89cq
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
- Warn: Project is vulnerable to: GHSA-9crc-q9x8-hgqq
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/autofix.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/unjs/listhen/autofix.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/autofix.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/unjs/listhen/autofix.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/unjs/listhen/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/unjs/listhen/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/unjs/listhen/ci.yml/main?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 2 third-party GitHubAction dependencies pinned
Reason
Found 3/28 approved changesets -- score normalized to 1
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: topLevel 'contents' permission set to 'read': .github/workflows/autofix.yml:9
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 10 are checked with a SAST tool
Score
3.7
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More