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

toa

v3.3.0

Published

A pithy and powerful web framework.

Downloads

620

Readme

Toa

简洁而强大的 web 框架。

Toa

NPM version Build Status js-standard-style Coverage Status Downloads

Thanks to Koa and it's authors

Demo

const ilog = require('ilog')
const Toa = require('toa')

const app = new Toa()

app.use(function () {
  this.body = 'support sync function middleware!\n'
})

app.use(function (next) {
  this.body += 'support thunk function middleware!\n'
  next()
})

app.use(function * () {
  this.body += yield Promise.resolve('support generator function middleware!\n')
})
// support in Node.js v8
app.use(async function () {
  this.body += await Promise.resolve('support async/await function middleware!\n')
})

app.listen(3000, () => ilog.info('App start at: 3000'))

TypeScript Demo

import { Toa } from 'toa'

const app = new Toa()

app.use(function () {
  this.body = 'support sync function middleware!\n'
})

app.use(function (next) {
  this.body += 'support thunk function middleware!\n'
  next()
})

app.use(function * () {
  this.body += yield Promise.resolve('support generator function middleware!\n')
})

app.use(async function () {
  this.body += await Promise.resolve('support async/await function middleware!\n')
})

app.listen(3000, () => console.log('App start at 3000'))

With HTTP/2

// Visit: https://127.0.0.1:3000/
const http2 = require('http2')
const fs = require('fs')
const Toa = require('toa')
const server = http2.createSecureServer({
  key: fs.readFileSync('./localhost.key'),
  cert: fs.readFileSync('./localhost.crt')
})

const app = new Toa(server)
app.use(function () {
  this.body = 'Hello World!\n-- toa'
})

app.listen(3000, () => console.log('https://127.0.0.1:3000/'))

Install

npm install toa

Toa 简介

ToaKoa 的改进版。

Toa 修改自 Koa,基本架构原理与 Koa 相似,contextrequestresponse 三大基础对象几乎一样。但 Toa 是基于 thunks 组合业务逻辑,来实现异步流程控制和异常处理。

Toa 的异步核心是 thunk 函数,支持 node.js v0.10.x,但在支持 generator 的 node 环境中(io.js, node.js >= v0.11.9)将会有更好地编程体验:用同步逻辑编写非阻塞的异步程序

ToaKoa 学习成本和编程体验是一致的,两者之间几乎是无缝切换。但 Toa 去掉了 Koa级联(Cascading) 逻辑,强化中间件,强化模块化组件,尽量削弱第三方组件访问应用的能力,使得编写大型应用的结构逻辑更简洁明了,也更安全。

koa Process

koa Process

Toa Process

Toa Process

功能模块

与 Koa 一样, Toa 也没有绑定多余的功能,而仅仅提供了一个轻量优雅的函数库,异步控制处理器和强大的扩展能力。

使用者可以根据自己的需求选择独立的功能模块或中间件,或自己实现相关功能模块。以下是 Toajs 提供的基础性的功能模块。它们已能满足大多数的应用需求。


Bench

API

使用手册

Application

Context

Request

Response

Change Log