Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
An elegant HTTP listener.
You can run your applications in localhost with typescript support and watch mode using listhen
CLI:
Create index.ts
:
export default (req, res) => {
res.end("Hello World!");
};
Using unjs/h3:
import { createApp, eventHandler } from "h3";
export const app = createApp();
app.use("/", () => "Hello world!");
Use npx to invoke listhen
command:
npx listhen -w ./index.ts
Install package:
# pnpm
pnpm i listhen
# npm
npm i listhen
# yarn
yarn add listhen
Import into your Node.js project:
// CommonJS
const { listen, listenAndWatch } = require("listhen");
// ESM
import { listen, listenAndWatch } from "listhen";
const handler = (req, res) => {
res.end("Hi!")
}
// listener: { url, getURL, server, close, ... }
const listener = await listen(handle, 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 cert and key are path 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 inline cert and key instead of reading from filesystem. In this case, they should start with --
.
showURL
true
(force disabled on test environment)Show a CLI message for listening URL.
baseURL
/
open
false
(force disabled on test and production environments)Open URL in browser. Silently ignores errors.
clipboard
false
(force disabled on test and production environments)Copy URL to 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 signal is received on process.
MIT. Made with 💖
v1.2.0
FAQs
👂 Elegant HTTP Listener
The npm package listhen receives a total of 949,756 weekly downloads. As such, listhen popularity was classified as popular.
We found that listhen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.