Gathering detailed insights and metrics for listhen
Gathering detailed insights and metrics for listhen
Gathering detailed insights and metrics for listhen
Gathering detailed insights and metrics for listhen
npm install listhen
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
457 Stars
318 Commits
30 Forks
4 Watching
6 Branches
31 Contributors
Updated on 26 Nov 2024
TypeScript (99.53%)
JavaScript (0.47%)
Cumulative downloads
Total Downloads
Last day
-0.9%
191,828
Compared to previous day
Last week
4.2%
1,075,609
Compared to previous week
Last month
3.6%
4,529,497
Compared to previous month
Last year
135.2%
44,039,556
Compared to previous year
Elegant HTTP listener!
✅ 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
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
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)
port
process.env.PORT
or 3000 or memorized random (see get-port-please)Port to listen.
hostname
process.env.HOST || '0.0.0.0'
Default hostname to listen.
https
false
Listen on HTTPS with SSL enabled.
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 is 1
.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 --
.
showURL
true
(force disabled on a test environment)Show a CLI message for the listening URL.
baseURL
/
open
false
(force disabled on test and production environments)Open the URL in the browser. Silently ignores errors.
clipboard
false
(force disabled on test and production environments)Copy the URL to the clipboard. Silently ignores errors.
isTest
process.env.NODE_ENV === 'test'
Detect if running in a test environment to disable some features.
autoClose
true
Automatically close when an exit
event, SIGTERM
, SIGINT
or SIGHUP
signal is received in the process.
publicURL
The public URL to show in the CLI output
qr
true
Print QR Code for public address.
public
false
for development or when hostname
is localhost
and true
for productionWhen enabled, listhen tries to listen to all network interfaces. You can also enable this option using --host
CLI flag.
ws
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!
Published under the MIT license.
Made by @pi0 and community 💛
🤖 auto updated with automd
No vulnerabilities found.
Reason
12 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 2/28 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
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