npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tsfinch

v0.5.2

Published

A simple typescript HTTP server.

Readme

Finch

一个简单的TypeScript服务框架。

简介

用 TypeScript 写的;
跟其他的中间件系统差不多;
对原始的 Node 本身的 request( IncomingMessage ) 和 response ( ServerResponse) 没有做任何封装;用起来比较方便。

安装

npm install tsfinch

快速运行

import {Finch,log} from "tsfinch";

let app = new Finch();// app 是服务的名字可以随便起
app.listen(3000);

尽管这个服务总是返回404错误;但他已经运行起来了。

使用案例

import {Finch, postParser, responseWare} from "tsfinch";

//初始化一个APP
let app = new Finch();

//设置一个静态文件的路径,应用会在此处查找静态文件并向请求者自动返回
app.staticDir = "./files";

//一个中间件的使用示例:当用户访问域名根目录时,直接返回"HELLO WORLD!"
app.use('/', (req, res, next) => { //中间件函数
  res.writeHead(200, {'content-type': 'text/plain'});// 'res' 对象就是原生的 'ServerResponse' 对象
  res.write('HELLO WORLD!');
  res.end();
});

//使用自带的 responseWare 可以简化操作
app.use('/responseJson', (req, res, next) => {
  responseWare.rJson(res, {"Hello": "World"});
});

//多个中间件套用
app.use('/upload', postParser);
app.use('/upload', (req, res) => {

  let fieldStr = JSON.stringify(req.postFields);
  let fileStr = JSON.stringify(req.postFiles);

  //使用内置的日志组件打印上一步被中间件解析的文件信息;
  log(fieldStr+"\r\n"+fileStr);

  res.writeHead(200, {'content-type': 'text/plain'});
  res.write('received upload:\n\n');
  res.end();
});

//开始监听端口进行服务
app.listen(3000);

Finch类

提供HTTP服务的主类

属性

  • staticDir 静态文件路径
  • logger FinchLog 日志实例,详见下文;
  • enableLogger 是否开启 FinchLog 日志实例;
  • handles 用以处理请求路径所对应的中间件集合;
  • server HTTP[S] 服务;Node原生;

方法

  • listen(port: number) 监听端口
  • use(handle: string, middleWare: middleWareFunction): void 使用中间件
  • all(middleWare: middleWareFunction):void 对所有句柄使用中间件

FinchLog类

内置用来打印日志的类

属性

  • logFileMaxLines 日志文件的最大行数,限制日志文件的大小
  • maxLogFilesCount 最多储存多少个日志文件
  • logStorageDir 日志文件的路径

方法

  • log(message: string, color?: FinchLogColor) 打印日志的文件

responseWare 方法组

  • responseWare.rJson(response: ServerResponse, msg: string | object) JSON
  • responseWare.r404(response:ServerResponse)
  • responseWare.r403(response:ServerResponse)
  • responseWare.rStaticFiles(res:ServerResponse, staticFilePath:string) 返静态文件
  • responseWare.rDownloadFile(res:ServerResponse, dfp:string, dfn?:string) 返下载文件
  • responseWare.rRedirect(response: ServerResponse, url: string) 返回一个HTML页面让他重新跳转

cookieParser 中间件

使用“cookie”解析cookie

postParser 中间件

使用 “BusBoy” 解析POST请求