标签:
今天开始学习目前呼声很高的koa模块,不过目前使用koa还是要用
--harmony-generator
标识,即便在刚出的nodejs 12上也是如此~,io.js倒是不需要,去年的nodejs和iojs分派不知道会不会带来什么大的变革,不过既然koa目前呼声这么高,肯定有他值得学习的地方,所以先搞着吧,多学点总比不学好。
这篇文章把koa依赖的模块列举一下,以后再自己学习koa的过程中减少一点查询的过程,也算是nodejs打基础的第一步吧~
Higher level content negotiation based on negotiator. Extracted from koa for general use. In addition to negotiator, it allows:
- Allows types as an array or arguments list, ie ([‘text/html‘, ‘application/json‘]) as well as (‘text/html‘, ‘application/json‘).
- Allows type shorthands such as json.
- Returns false when no types match
- Treats non-existent headers as *
一个比较高级的API用来http处理请求中的接受类型,比如: 判断请求可接收的类型
这个本身包含在koa里面的,现在是提取出来可以作为其他用途
https://www.npmjs.com/package/accepts
Generator based control flow goodness for nodejs and the browser, using promises, letting you write non-blocking code in a nice-ish way.
基于generator语法的控制流,koa的generator就是来自这个?
https://www.npmjs.com/package/co
Compose generator and async/await middleware like koa. Allows to use both generator functions and async/await functions.
撰写跟koa风格一致的代码,koa包含这个。。。傻傻分不清楚
https://www.npmjs.com/package/composition
Create and parse HTTP Content-Disposition header
貌似用于文件下载的时候自动适配文件的类型把类型写入Content-Type
https://www.npmjs.com/package/content-disposition
2015-2-27保存草稿...明天继续
Create and parse HTTP Content-Type header according to RFC 7231
用来处理Content-Type
头信息的
https://www.npmjs.com/package/content-type
cookie is a basic cookie parser and serializer. It doesn‘t make assumptions about how you are going to deal with your cookies. It basically just provides a way to read and write the HTTP cookie headers.
See RFC6265 for details about the http header for cookies.
只是提供一个读写cookie的API
https://www.npmjs.com/package/cookie
tiny node.js debugging utility modelled after node core‘s debugging technique.
貌似就是一个封装的打印log的小东西?待研究~
https://www.npmjs.com/package/debug
Node method and accessor delegation utilty.
代理?不明,待研究
https://www.npmjs.com/package/delegates
Destroy a stream.
用来摧毁一个strem对象
https://www.npmjs.com/package/destroy
inject an error listener into a stream
给stream对象注入一个错误监听
https://www.npmjs.com/package/error-inject
Escape HTML entities
这个。。。顾名思义了,跟前端的escape一个意思
https://www.npmjs.com/package/escape-html
HTTP response freshness testing
貌似是一个根据Etag来判断是否cache的东西,如果是cache的就直接返回304
https://www.npmjs.com/package/fresh
Assert with status codes. Like ctx.throw() in Koa, but with a guard.
通过状态码进行断言?猜测是用来判断请求状态的,全部代码只有33行...
https://www.npmjs.com/package/http-assert
Create HTTP errors for Express, Koa, Connect, etc. with ease.
又是一个从koa里面分离出去的模块,主要作用是用来简单得创建http错误信息
https://www.npmjs.com/package/http-errors
The ultimate javascript content-type utility.
Similar to node-mime, except:
- No fallbacks. Instead of naively returning the first available type, mime-types simply returns false, so do var type = mime.lookup(‘unrecognized‘) || ‘application/octet-stream‘.
- No new Mime() business, so you could do var lookup = require(‘mime-types‘).lookup.
- Additional mime types are added such as jade and stylus via mime-db
- No .define() functionality
Otherwise, the API is compatible.
最终版的MIME帮助API,重新定义了API实现,更加方便,也更加健全
https://www.npmjs.com/package/mime-types
Execute a callback when a request closes, finishes, or errors
在请求结束的时候调用一个回调
https://www.npmjs.com/package/on-finished
return whitelisted properties of an object
返回白名单中的值。其实就是根据一个列表获取一个对象中的部分属性返回一个obj
https://www.npmjs.com/package/only
parse a url with memoization
返回req.url,返回结果和url.parse一样(不知道这个url是不是req.url),多次对同一个req调用该方法会直接返回缓存的结果,不在进行parse
https://www.npmjs.com/package/parseurl
HTTP status utility for node.
http状态工具status(403) // => ‘Forbidden‘
,可以通过code转换成msg,也可以通过msg转换成code
https://www.npmjs.com/package/statuses
Infer the content-type of a request.
判断一个请求的content-type
https://www.npmjs.com/package/type-is
Manipulate the HTTP Vary header
推断不同的http头的内容?貌似可以根据头来判断值
https://www.npmjs.com/package/vary
好了,基本把所有的都列出来了,在这个过程中发现有很多的都是从koa中分离出来的,所有大体上可以认为koa基本就是从头开始的(貌似是屁话)。还有两个没列,但是也没必要了,名字如下:
你们懂的
标签:
原文地址:http://www.cnblogs.com/jokcy/p/4306158.html