Socket
Socket
Sign inDemoInstall

listhen

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

listhen - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

dist/cli.cjs

11

dist/index.d.ts
import { Server, RequestListener } from 'node:http';
import { Server as Server$1 } from 'node:https';
import { GetPortInput } from 'get-port-please';
import { ConsolaInstance } from 'consola';

@@ -29,2 +30,7 @@ interface Certificate {

}
interface WatchOptions {
cwd: string;
entry: string;
logger: ConsolaInstance;
}
interface ShowURLOptions {

@@ -43,4 +49,7 @@ baseURL: string;

}
declare function listen(handle: RequestListener, options_?: Partial<ListenOptions>): Promise<Listener>;
export { Certificate, HTTPSOptions, ListenOptions, Listener, ShowURLOptions, listen };
declare function listenAndWatch(input: string, options?: Partial<ListenOptions & WatchOptions>): Promise<Listener>;
export { Certificate, HTTPSOptions, ListenOptions, Listener, ShowURLOptions, WatchOptions, listen, listenAndWatch };

51

package.json
{
"name": "listhen",
"version": "1.0.4",
"description": "",
"version": "1.1.0",
"description": "👂 Elegant HTTP Listener",
"repository": "unjs/listhen",

@@ -9,5 +9,10 @@ "license": "MIT",

".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"require": "./dist/index.cjs"
},
"./cli": {
"types": "./dist/cli.d.ts",
"import": "./dist/cli.mjs",
"require": "./dist/cli.cjs"
}

@@ -17,2 +22,6 @@ },

"types": "./dist/index.d.ts",
"bin": {
"listen": "./dist/cli.cjs",
"listhen": "./dist/cli.cjs"
},
"files": [

@@ -23,25 +32,28 @@ "dist",

"dependencies": {
"citty": "^0.1.2",
"clipboardy": "^3.0.0",
"colorette": "^2.0.19",
"consola": "^3.2.3",
"defu": "^6.1.2",
"get-port-please": "^3.0.1",
"http-shutdown": "^1.2.2",
"ip-regex": "^5.0.0",
"jiti": "^1.19.1",
"mlly": "^1.4.0",
"node-forge": "^1.3.1",
"ufo": "^1.1.1"
"pathe": "^1.1.1",
"ufo": "^1.1.2"
},
"devDependencies": {
"@types/node": "^18.15.0",
"@types/node-forge": "^1.3.1",
"@vitest/coverage-c8": "^0.29.2",
"changelogen": "^0.5.1",
"eslint": "^8.36.0",
"eslint-config-unjs": "^0.1.0",
"jiti": "^1.17.2",
"prettier": "^2.8.4",
"typescript": "^4.9.5",
"unbuild": "^1.1.2",
"vitest": "^0.29.2"
"@types/node": "^20.4.2",
"@types/node-forge": "^1.3.3",
"@vitest/coverage-v8": "^0.33.0",
"changelogen": "^0.5.4",
"eslint": "^8.45.0",
"eslint-config-unjs": "^0.2.1",
"ip-regex": "^5.0.0",
"prettier": "^3.0.0",
"typescript": "^5.1.6",
"unbuild": "^1.2.1",
"vitest": "^0.33.0"
},
"packageManager": "pnpm@7.29.1",
"packageManager": "pnpm@8.6.8",
"scripts": {

@@ -51,2 +63,3 @@ "build": "unbuild",

"lint": "eslint --ext .ts . && prettier -c src test",
"lint:fix": "eslint --fix --ext .ts . && prettier -w src test",
"play": "jiti test/fixture/app",

@@ -53,0 +66,0 @@ "release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",

@@ -11,8 +11,9 @@ # 👂 listhen

## Features
## Features
- Built-in CLI To run your applications with watch mode and typescript support (with [unjs/jiti](https://github.com/unjs/jiti))
- Promisified interface for listening and closing server
- Work with express/connect or plain http handle function
- Support HTTP and HTTPS
- Assign a port or fallback to human friendly alternative (with [get-port-please](https://github.com/unjs/get-port-please))
- Assign a port or fallback to human friendly alternative (with [unjs/get-port-please](https://github.com/unjs/get-port-please))
- Generate listening URL and show on console

@@ -26,8 +27,34 @@ - Copy URL to clipboard (dev only by default)

## Install
## Quick Usage (CLI)
Install using npm:
You can run your applications in localhost with typescript support and watch mode using `listhen` CLI:
Create `app.ts`:
```ts
export default (req, res) => {
res.end("Hello World!");
};
```
Use npx to invoke `listhen` command:
```sh
npx listhen -w ./app.ts
```
## Usage (API)
Install package:
```bash
# pnpm
pnpm i listhen
# npm
npm i listhen
# yarn
yarn add listhen
```

@@ -39,37 +66,17 @@

// CommonJS
const { listen } = require('listhen')
const { listen, listenAndWatch } = require("listhen");
// ESM
import { listen } from 'listhen'
import { listen, listenAndWatch } from "listhen";
```
## Usage
**Function signature:**
```ts
const { url, getURL, server, close } = await listen(handle, options?)
```
const handler = (req, res) => {
res.end("Hi!")
}
**Plain handle function:**
```ts
listen((_req, res) => {
res.end('hi')
})
// listener: { url, getURL, server, close, ... }
const listener = await listen(handle, options?)
```
**With express/connect:**
```ts
const express = require('express')
const app = express()
app.use('/', ((_req, res) => {
res.end('hi')
})
listen(app)
```
## Options

@@ -150,2 +157,3 @@

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/listhen?style=flat&colorA=18181B&colorB=F0DB4F

@@ -152,0 +160,0 @@ [npm-version-href]: https://npmjs.com/package/listhen

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc