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

thinkkoa

v2.4.14

Published

A lightweight, scalable for agile development Node.js web framework, based on koa2.

Downloads

43

Readme

ThinkKoa

介绍

npm version Build Status dependencies Status Package Quality

A lightweight, scalable for agile development Node.js web framework, based on koa2.

ThinkKoa - 轻量级可扩展的敏捷开发Node.js框架,支持ES6/7全新特性,支持Koa、Express中间件,基于koa2。

特性

  • 基于koa2

ThinkKoa基于著名的Node.js框架koa2进行了薄封装。扩展了Koa的功能,能够迅速的进行Web开发。

  • 支持Koa/Express中间件

通过简单的引入机制,ThinkKoa可以很好的支持Koa中间件(包括Koa1及Koa2)。还提供了useExp()来使用Express的中间件。大大提升了框架的扩展性及开源模块利用率。

  • 为敏捷开发而生

ThinkKoa是在ThinkKoa团队3年的Node.js项目开发积累中酝酿诞生的,以提升团队开发效率、助力敏捷开发为目的。框架经过公司多个互联网产品上线、迭代以及大流量大并发的考验。

  • 支持多种项目结构和多种项目环境

ThinkKoa默认支持单模块模式,适合简单快速的项目。业务复杂的项目,可以开启多模块支持,功能划分更加清晰。ThinkKoa支持Nginx代理以及pm2部署,适合对稳定性和效率有要求的生产环境。

  • 支持灵活的自定义路由

ThinkKoa除默认的单模块模式(controller/action)及多模块模式(module/controller/action)路由规则以外,还支持用户定制路由。 在项目中增加路由文件配置即可灵活的支持Restful等各种自定义路由。

  • 拥抱 Node.js 8 LTS, 使用 ES6/7 特性来开发项目

Node.js 8支持99%的ES6新特性,并且相对6.0版本提升20%性能。现在使用 async/await 等一系列新特性,让Node.js开发变得赏心悦目。

const {controller, helper} = require('thinkkoa');
const user = require('../model/user.js');

//user controller, controller/user.js
module.exports = class extends controller {
    //login action
    async loginAction(){
        //If it is a get request, the login page is displayed directly
        if(this.isGet()){
          return this.render();
        }
        //Obtaining data by post method
        let name = this.post('username');
        if (helper.isEmpty(name)) {
          return this.fail('username is required');
        }
        let userModel = new user(this.app.config('config.model', 'middleware'));
        //Username matches the corresponding entries in the database.
        let result = await userModel.where({name: name, phonenum: {"not": ""}}).find();
        if(!result){
          return this.fail('login fail'); 
        }
        //Written into session
        await this.session('userInfo', result);
        return this.ok('login success'); 
    }
}

上面的代码我们使用了 ES6 里的 class, let 以及 ES7 里的 async/await 等特性,虽然查询数据库和写入 Session 都是异步操作,但借助 async/await,代码都是同步书写的。

文档

中文文档

快速开始

全局安装thinkkoa_cli

npm install -g [email protected]

创建项目

在合适的位置执行命令

think new project_name

进入这个目录

cd project_name

安装依赖

npm install

启动服务

npm start

开始访问

打开浏览器,访问http://localhost:3000

协议

MIT