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

manys

v1.0.2

Published

Light weight Asynchronous Concurrency Control.

Readme

manys

Light weight Asynchronous Concurrency Control.

轻量级的异步并发控制。

特点

  • 轻量级的,无第三方依赖
  • 异步并发控制

安装

npm install manys

使用参数

manys(array, number, callback(value, resolve, reject))
  • arrat 进行异步操作的数组
  • number 设置最大并发数量
  • callback 对数组中的每一元素进行的操作
    • value 数组中的元素
    • resolve 异步操作处理完后进行返回 成功状态,并且传入参数可选
      • 传入的参数将会统一传入到所有异步并发任务完成后的 then 中处理
    • reject 异步操作处理出现错误时,进行返回错误信息
      • 传入的参数将会统一传入到所有异步并发任务完成后的 catch 中处理

通过抓取到https://cnodejs.org/ 这个网站首页的 40 条文章链接后,再进行异步请求获取每个链接的页面。

由于并发过高,会导致返回503,这时需要控制异并发的数量。

  • 使用axios 发起请求

  • cheerio 用来获取指定的内容。(nodejs版 JQuery)

  • 自豪的使用 manys 控制 异步并发数

const axios = require('axios');
const cheerio = require('cheerio');
const url = require('url');
const manys = require('manys');

const href = 'https://cnodejs.org';

// 抓取url
axios.get(href)
      .then(res => {
        let $ = cheerio.load(res.data);
        let node = $('#topic_list a.topic_title');
        let list = [];
        node.each((index, value) => list.push(url.resolve(href, value.attribs.href)));
        // list 数组存放了首页的 40 条文章 url
        return list;
      })
      .then(list => {

        // 异步并发数设置为 10 ,防止并发过高造成请求失败
        manys(list, 10, (value, resolve, reject) => {
          // 进行的异步操作
          axios.get(value).then(res => {
                            // 我把文章页面的标题抓取下来,并传入 resolve 中
                            let $ = cheerio.load(res.data);
                            let title = $('.topic_full_title').text();
                            // 异步操作成功后,再对返回值进行处理,再统一传入到所有异步并发任务完成后的 then 中处理
                            resolve(title);
                          })
                          // 错误处理,可以就在当前处理,也可以统一传入到所有异步并发任务完成后的 catch 中处理
                          .catch(err => reject(err));
        })
        // 所有异步并发任务完成后,返回的值 或 错误信息,将以数组的形式,全部传入 then 或 catch中 
        .then(data => console.log(data))  // 打印出返回的所有文章标题的数组
        .catch(err => {throw err});

      })
      .catch(err => err);