CNode

What is the essence of "Express" in nodejs

问答
Ssafarishi发布于9 年前最后回复9 年前2 回复2999 浏览0 收藏

I read some source code of express in github, bug I have a detail that does not understand const express = require('express') const app = express()

app.use((req, res, next) => { // res is what? is the Writable Stream // debug this code I know the res is a Stream, but I can not distinguish the type of Stream is the writeable or readable })

// reference from nodejs api http.createServer((req, res) => { // res is the same as the express's res // in the doc of nodejs api // res is an http.ServerResponse, which is a Writable Stream })

but when it comes to the express app's callback -> res Excuse me?

查看回复

回复 (2)

G
godghdai#1·9 年前

writeable

S
safarishi#2·9 年前

@godghdai thanks

I have found the answer from the nodejs api.

Because express callback res in its prototype you can find it is the type of ServerResponse

// the below is the nodejs document Class: http.ServerResponse# Added in: v0.1.17 This object is created internally by an HTTP server--not by the user. It is passed as the second parameter to the 'request' event.

The response implements, but does not inherit from, the Writable Stream interface. This is an EventEmitter with the following events:

参与回复
登录后即可参与回复。登录