
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
generator-naive
Advanced tools
generator-naive取名为naive的目的是让你明白膜法的力量,以至于你不总在Node.js项目开发过程中显得那么too young, too simple, sometimes naive.

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

Koa2MySQLsql文件,示例sql在sql/too_young_too_simple.sql。config/local.js文件,设置本地sql用户名和密码。以保证成功连接数据库。localhost:3000/test,查看返回结果。不需要在通过JSON文件配置化注册路由,将router和handler合二为一,你只需要更改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);
使用generator-naive,SQL操作则更加简单,你不用关心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');
SQL注入,使用joi做鉴权中间件express 支持yeomanFAQs
too young too simple, sometime naive
We found that generator-naive demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.