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

@yu1596882018/server-sdk

v1.2.2

Published

Server-side utilities and tools for Node.js applications

Readme

@yu1596882018/server-sdk

Node.js 应用程序的服务器端工具和实用程序

📦 安装

npm install @yu1596882018/server-sdk
# 或者
yarn add @yu1596882018/server-sdk

🚀 功能特性

  • 二维码生成: 从文本或 URL 生成二维码
  • 日志工具: 支持不同级别和格式的高级日志记录
  • 服务器工具: 常用的服务器端辅助函数

📖 API 参考

二维码生成

const { generateQRCode } = require('@yu1596882018/server-sdk');

// 从文本生成二维码
const qrCode = await generateQRCode('https://example.com');

// 使用自定义选项生成二维码
const qrCodeWithOptions = await generateQRCode('Hello World', {
  width: 300,
  height: 300,
  color: '#000000',
  backgroundColor: '#ffffff',
});

日志工具

const { Logger } = require('@yu1596882018/server-sdk');

const logger = new Logger({
  level: 'info',
  format: 'json',
  output: 'file', // 或 'console'
});

logger.info('应用程序已启动');
logger.error('发生错误', { error: '详细信息' });
logger.warn('警告信息');
logger.debug('调试信息');

服务器工具

const { ServerUtils } = require('@yu1596882018/server-sdk');

// 获取服务器信息
const serverInfo = ServerUtils.getServerInfo();

// 验证配置
const isValid = ServerUtils.validateConfig(config);

🔧 配置

日志配置

{
  level: 'info',           // 日志级别: error, warn, info, debug
  format: 'json',          // 输出格式: json, text
  output: 'console',       // 输出目标: console, file
  filePath: './logs',      // 日志文件路径 (当 output 为 'file' 时)
  maxSize: '10m',          // 最大日志文件大小
  maxFiles: 5              // 最大日志文件数量
}

二维码配置

{
  width: 200,              // 二维码宽度
  height: 200,             // 二维码高度
  color: '#000000',        // 二维码颜色
  backgroundColor: '#ffffff', // 背景颜色
  margin: 4,               // 二维码周围边距
  errorCorrectionLevel: 'M' // 纠错级别: L, M, Q, H
}

📝 使用示例

Express.js 集成

const express = require('express');
const { generateQRCode, Logger } = require('@yu1596882018/server-sdk');

const app = express();
const logger = new Logger();

app.get('/qr/:text', async (req, res) => {
  try {
    const qrCode = await generateQRCode(req.params.text);
    res.type('image/png').send(qrCode);
    logger.info('二维码已生成', { text: req.params.text });
  } catch (error) {
    logger.error('生成二维码失败', { error: error.message });
    res.status(500).json({ error: '生成二维码失败' });
  }
});

app.listen(3000, () => {
  logger.info('服务器已启动,端口 3000');
});

Koa.js 集成

const Koa = require('koa');
const { generateQRCode, Logger } = require('@yu1596882018/server-sdk');

const app = new Koa();
const logger = new Logger();

app.use(async (ctx, next) => {
  const start = Date.now();
  await next();
  const ms = Date.now() - start;
  logger.info(`${ctx.method} ${ctx.url} - ${ms}ms`);
});

app.use(async ctx => {
  if (ctx.path.startsWith('/qr/')) {
    const text = ctx.path.slice(4);
    const qrCode = await generateQRCode(text);
    ctx.type = 'image/png';
    ctx.body = qrCode;
  } else {
    ctx.body = 'Hello World';
  }
});

app.listen(3000);

🛠️ 开发

构建

# 安装依赖
yarn install

# 构建包
yarn build

# 运行测试
yarn test

项目结构

server-sdk/
├── index.js          # 主入口文件
├── index.d.ts        # TypeScript 定义
├── utils/            # 工具函数
│   ├── codeToQR.js   # 二维码生成
│   └── logUtil.js    # 日志工具
└── README.md         # 本文档

📄 许可证

MIT 许可证 - 详情请查看 LICENSE

🤝 贡献

  1. Fork 本仓库
  2. 创建你的功能分支 (git checkout -b feature/amazing-feature)
  3. 提交你的更改 (git commit -m '添加一些很棒的功能')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 开启一个 Pull Request

📞 支持

🔄 更新日志

v1.0.8

  • 初始版本发布
  • 二维码生成功能
  • 高级日志工具
  • 服务器工具函数

yu1596882018 用 ❤️ 制作