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

mzbl_node_utils

v0.0.8

Published

public node utils

Readme

node后端通用工具类


目录


如何使用

npm install mzbl_node_utils

    var utils = require('mzbl_node_utils');

公共类

  1. 如何使用
    var publicMethod = utils.public;
  1. streamToBuffer(stream) 将stream转为Buffer

  2. publicRequest(data) 公共请求方法 返回Promise

    | 参数名 | 类型 | 备注 | | ----- | --- | ---- | | data.url | string | 请求地址 default '' | | data.method | string | 请求方法 | | data.header | object | 请求头 default {} | | data.body | object | 请求数据 default {} |


数据库查询

  1. 实例化
    var dbMethod = new utils.sql('localhost:9800');
  1. sql查询
  • 方法名 query(data)

  • 查询参数

    | 参数名 | 类型 | 备注 | | ----- | --- | ---- | | data.name | string | 需要查询的数据库名 | | data.sql | string | sql语句 | | data.params | object | 查询参数 | | data.isInsertRecord | boolean | 执行成功是否插入查询记录 | | data.programName | string | 执行sql的程序名称(非必填) |

  • e.g

    var dbMethod = new utils.sql('localhost:9800');
    var sqlData = {
        name: 'testDb',
        sql: 'select 1=1 as test;',
        params: {},
        isInsertRecord: false,
        programName: 'test',
    }
    dbMethod.query(sqlData)
    .then(msg => { console.log(msg) });

  1. sql配置查询
  • 方法名: queryBySqlConfig(data)

  • 查询参数

    | 参数名 | 类型 | 备注 | | ----- | --- | ---- | | data.name | string | sql配置名 | | data.program | string | sql程序名 | | data.params | boolean | 查询参数 |

  • e.g

    var dbMethod = new utils.sql('localhost:9800');
    var sqlData = {
        name: 'testConfig',
        program: 'test',
        params: {},
    }
    dbMethod.queryBySqlConfig(sqlData)
    .then(msg => { console.log(msg) });

  1. sequelize查询
  • 方法名: querying(data)

  • 查询参数

    | 参数名 | 类型 | 备注 | | ----- | --- | ---- | | data.dbName | string | 数据库名 | | data.tableName | string | 数据表名 | | data.method | string | sequelize查询方法 | | data.condition | array object | 查询条件 | | data.condition.attributes | object | 查询字段 | | condition.attributes.fn | string | 函数名 | | condition.attributes.col | array | 表字段 | | condition.attributes.name | string | 自定义字段名 | | condition.attributes.fnArr | array | 函数参数 | | condition.attributes.paramPosition | 'front' | 'last' | 参数位置 | | data.condition.where | object | 查询where条件 | | data.condition.order | array array | 查询排序 |

  • e.g

    var dbMethod = new utils.sql('localhost:9800');
    var sqlData = {
        dbName: 'data_system',
        tableName: 'tbsqlconfig',
        method: 'findAll',
        condition: {
            attributes: [
                'id',
                {
                    fn: 'date_format',
                    col: [`createDate`],
                    name: 'createDate',
                    fnArr: ['%Y-%m-%d %H:%i:%s'],
                    paramPosition: 'last',
                }
            ],
            where: {
                id: 1,
            },
            order: [
                ['id','DESC'],
            ]
        },
    }
    dbMethod.querying(sqlData)
    .then(msg => { console.log(msg) });

  1. redis查询
  • 方法名: redis(data)

  • 查询参数

    | 参数名 | 类型 | 备注 | | ----- | --- | ---- | | data.dbName | string | sql配置名 | | data.methodName | string | sql程序名 | | data.params | array | 查询参数 |

  • e.g

    var dbMethod = new utils.sql('localhost:9800');
    var sqlData = {
        dbName: 'defaultDb',
        methodName: 'lrangeAsync',
        params: ['xcfunds_s19e01<|>awardPool<|>sub', 0, -1],
    }
    dbMethod.redis(sqlData);
    .then(msg => { console.log(msg) });

集成的modules列表

  1. logger
  2. moment
  3. jsonwebtoken
  4. alipaySdk