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 🙏

© 2025 – Pkg Stats / Ryan Hefner

stat-table

v2.2.3

Published

simple framework for user stat on backend

Readme

stat-table

服务器端用户留存统计的简易框架

模块暂时只支持日留存统计,后续可能会加入周留存率的计算。如果用户数庞大,建议将留存数据放在单独的redis服务器上,减少生成统计数据过程中可能对业务服务器造成的冲击。

依赖环境

node   v4.x
redis  v3.2.x

示例

使用模块

导出对象供使用,写在一个公用文件中,比如common/stat.js

const StatTable = require('stat-table');
const stat = new StatTable({host, port, db});//es6的写法,连接redis的配置信息
module.exports = stat;

注入代码

在注册和登录的地方分别调用相关的记录函数

stat.recordRegister(userId);//注册
stat.recordLogin(userId);//登录

每日统计

设置一个定时任务,在每天23点55分左右执行以下函数,date为可选的日期字符串,格式为YYYYMMDD,不提供该参数时默认取当天

stat.genMultiDayRetention(date, (err) => {});

导出结果

导出文件为csv格式,dirPath为文件路径;days是希望导出的最长多少天的留存率。例如,days为10,则会导出注册日之后10天的登录留存情况。

stat.exportRetention(dirPath, days, (err) => {});

结果格式

导出结果

其它功能

//baseDate均表示指定日期,格式为YYYYMMDD

//获取在指定日期注册,并在指定天数之后依然留存的用户id,afterNum为指定的天数
stat.getRetentionUserIds(baseDate, afterNum, (err, userIds) => {});

//获取在指定日期注册的用户id
stat.getRegisterUserIds(baseDate, (err, userIds) => {});

//获取在指定日期登录的用户id
stat.getLoginUserIds(baseDate, (err, userIds) => {});