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 🙏

© 2024 – Pkg Stats / Ryan Hefner

nodex-libs

v2.4.9

Published

A nodejs library

Downloads

179

Readme

nodex-libs

nodex-libs是一个基于nodejs的服务端程序库。其中包含在实际工程中可用的方法。可以简化nodejs程序开发。

特性

  • 所有API和接口都有完整的文档和类型标注。
  • 所有模块都使用最新的es6或es7的标准实现,所有异步任务都采用async/await的方式实现。
  • 提供基于标签和着色的原生日志方法。
  • 支持简洁的HTTP和HTTPS请求发起。
  • 支持基于Koa2的简化的HTTP/HTTPS服务器接口,提供干净简洁的错误处理工作流,支持完全可控的文件上传下载功能。
  • 提供了简洁的基于mysql连接池的数据库操作,支持mysql事务处理。
  • 提供常用的加hash算法、加密解密算法的接口。
  • 提供对基于Token、验证码、验证键的用户身份识别方法。
  • 提供简洁的数据格式/表单校验方法。
  • 提供基于flake的唯一编码生成方法。
  • 提供时间段、时间点等对日期时间的处理方法。

安装

npm install nodex-libs --save

使用样例

import

const libs = require('nodex-libs');

logger apis

const libs = require('nodex-libs');

libs.log.init('scope-name');

console.log(`log message`);
console.info(`info message`);
console.warn(`warning message`);
console.error(`error message`);

http server

const libs = require('nodex-libs');
const http = libs.http;

const args = {
    body: {},
    host: '127.0.0.1',
    port: 80,
    corn: true,
    log: true
};

let hello = (ctx) => {
    http.send(ctx, 'hello world.');
};

let about = (ctx) => {
    let ret = {
        name: 'nodex-libs test',
        info: 0
    };
    
    http.send(ctx, info);
};

let app = libs.http.webapp(args);

app.route((r)=>{
    r.get('/hello', hello);
    r.get('/about', about);
});

app.start();

mysql db

const libs = require('nodex-libs');
const mysql = libs.mysql;

mysql.init({
    host: '127.0.0.1',
    port: 3306,
    user: 'root',
    pswd: 'root'
});

{
    let sql = 'select * from test';
    let list = await mysql.query(sql);
    console.log(JSON.stringify(list));
}

{
    let sql = 'delete from test where id = 0';
    let ret = await mysql.query(sql);
    console.log(ret.affectedRows);
}

// transaction
do
{
    let tx = mysql.transaction();
    
    let ret = await tx.query('update test set status = 0 where id = 10');
    if(ret.affectedRows !== 1){
        tx.rollback();
        tx.release();
        break;
    }
    
    ret = await tx.query('update test data = 1 where id = 10');
    if(ret.affectedRows !== 1){
         tx.rollback();
         tx.release();
         break;
    }
    
    tx.commit();
    tx.release();
}
while(0);

MongoDB

const libs = require('nodex-libs');
const { Mongo } = libs.mongo;

const mongo = new Mongo({
    uri: 'mongodb://127.0.0.1:27017',
    database: 'test',
    useUnifiedTopology: true,
    useNewUrlParser: true
})
await mongo.connect();

const result = await mongo.query(db => db.collection('user').find().toArray());
console.log(result);

flakes unique ID:

const libs = require('nodex-libs');
const flakes = libs.flakes;

let f = flakes.create();
for(let i = 0; i < 10; i++){
    console.log(f.get());
}

Date and Time Operations:

const libs = require('nodex-libs');
const time = libs.time;

// now
let now = new time.TimePoint();
now = time.now();
console.log(now.toString('year-month-date hour:minute:second'));

let yesterday = new time.TimePoint(now.value() - time.MS_PER_DAY);
console.log(yesterday.toString());

let span = now.sub(yesterday);
console.log(`begin=${span.begin()}, end=${span.end()}`);

let thisWeek = now.thisWeek();
console.log(`begin=${thisWeek.begin()}, end=${thisWeek.end()}`);

let duration = new time.Duration(time.MS_PER_DAY);
console.log(`minutes: ${duration.accurateMinutes()}`)

Spawn

const libs = require('nodex-libs');
const spawn = libs.spawn;

let p = spawn.process();
p.on('out', (code, out, err) => {
    console.log(`${code} ${out} ${err}`);
});

for(let i = 0; i < 10; i++) {
    p.post(`echo`, [`command`, `${i}`]);
}
p.post(`npm`, [`--version`]);

License

MIT license