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

generator-naive

v0.1.1

Published

too young too simple, sometime naive

Readme

generator-naive

generator-naive取名为naive的目的是让你明白膜法的力量,以至于你不总在Node.js项目开发过程中显得那么too young, too simple, sometimes naive.

开始

  • npm install -g yo
  • npm install -g generator-naive
  • mkdir myapp && cd myapp
  • yo naive

介绍

generator-naive是一个基于Koa2Node.js服务端MVC脚手架。方便我们快速完成服务端接口开发。

技术栈

  • Koa2
  • MySQL

开始使用

  • 在本地数据库导入示例sql文件,示例sqlsql/too_young_too_simple.sql
  • 更改config/local.js文件,设置本地sql用户名和密码。以保证成功连接数据库。
  • 打开浏览器localhost:3000/test,查看返回结果。

特点

通过函数名注册路由

不需要在通过JSON文件配置化注册路由,将routerhandler合二为一,你只需要更改router目录下的函数即可实现路由注册:

const Router = require('./../framework').Router;
const testService = require('./../service/test_service');
const PATH = '/test';

class TestRouter extends Router {
  /**
   * getTest -> { "path": `${PATH}/insert`, "method": "GET" }
   * @param  {Object} ctx
   */
  async getTest(ctx) {
    let data = await testService.test();
    console.log(data);
    ctx.ok(data);
  }

  /**
   * getInsert -> { "path": `${PATH}/insert`, "method": "POST" }
   * @param  {Object} ctx
   */
  async postInsert(ctx) {
    let name = ctx.query.name;
    let data = await testService.insert(name);
    console.log(data);
    ctx.ok({});
  }
}

// mount router to path: PATH
module.exports = new TestRouter().mount(PATH);

更便捷的SQL

使用generator-naiveSQL操作则更加简单,你不用关心MySQL连接等相关操作,只需要在service层调用你写的dao即可。通过在dao层传入DbUtil.queryEscape的参数即可完成SQL查询。

const BaseClass = require('./../framework').BaseClass;
const DbUtil = require('../util/db_util');

class testDao extends BaseClass {
  constructor(...args) {
    super(...args);
    // regis your table
    this.table = 'user_info';
  }

  getAllData() {
    return DbUtil.queryEscape(`
      SELECT
        *
      FROM
        ${this.table}
    `);
  }

  insertUser(name) {
    return DbUtil.queryEscape(`
      INSERT INTO
        ${this.table}
        (name)
      VALUES
        (:name)
    `, {
      name: name
    });
  }
};

module.exports = new testDao();

日志

generator-naive使用winston来进行日志打印,你只需要在任何需要打印日志的地方引入winston即可完成日志打印。

winston.info('too young too simple, sometimes naive');

TODO

  • [ ] 日志打印记录完善
  • [ ] 防止SQL注入,使用joi做鉴权中间件
  • [ ] express 支持
  • [ ] 配置化yeoman