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

@kuankuan/k-server

v1.2.1

Published

A simple and easy-to-use server framework for Node.js

Readme

@kuankuan/k-server

一个简单易用的 Node.js 服务器框架。

特性

  • 轻量级模块化设计
  • 基于路由的请求处理
  • 内置日志记录,使用 @kuankuan/log-control
  • 自动响应压缩
  • 支持 TypeScript
  • 易于扩展和自定义

安装

npm install @kuankuan/k-server

用法

import { createServer, Router, restSender, Statue } from '@kuankuan/k-server';
import logControl from '@kuankuan/log-control';

const serverInstance = createServer({
  sender: restSender, // 设置响应发送器为 `restSender`(将以 REST 格式发送响应)
});

serverInstance.routers.main.addRouter(
  // 添加一个新的路由器
  new Router({
    matcher: 'test', // 自动匹配 /test 路径
    name: 'main', // 路由器名称
    onRootMatch: async (req, res, ctx, next) => {
      ctx.data = 'hello world'; // 向上下文添加数据
      await next(); // 调用下一个钩子
    },
  })
);

serverInstance.routers.main.addRouter(
  // 添加另一个路由
  new Router({
    matcher: 'notfound', // 自动匹配 /notfound 路径
    name: 'notfound', // 路由器名称
    onRootMatch: async (req, res, ctx, next) => {
      ctx.statue = Statue.NOT_FOUND; // 设置状态为 404
      await next(); // 调用下一个钩子
    },
  })
);

serverInstance.routers.main.addRouter(
  // 添加第三个路由
  new Router({
    matcher: 'error', // 自动匹配 /error 路径
    name: 'error', // 路由器名称
    onRootMatch: async (req, res, ctx, next) => {
      throw new Error('I am a error'); // 发送器会以 500 内部服务器错误响应
    },
  })
);

serverInstance.logApplication.addRecorder(
  // 向应用添加一个新的日志记录器。ConsoleRecorder 是内置的记录器,会将日志输出到控制台。
  new logControl.ConsoleRecorder({
    startLevel: logControl.Level.All, // 控制记录器的日志级别,输出所有日志
  })
);

serverInstance.server.listen(3000, () => {
  console.log('Server is running on http://localhost:3000'); // 启动服务器
});

脚本

  • npm run build — 使用 esbuild 和 TypeScript 构建项目
  • npm run lint — 对源文件运行 ESLint
  • npm run lint:fix — 运行 ESLint 并自动修复问题
  • npm run test — 构建并运行测试
  • npm run prettier — 使用 Prettier 格式化代码

许可证

本项目采用 Mozilla Public License 2.0 许可。详情请参阅 LICENSE