4

I have just started studying node.js and express, the documentation of express on the home page is just too simple for me as a beginner.

for example,

app.configure('development', function(){
    app.use(express.static(__dirname + '/public'));
    ...
});

It may seems very obvious to you, but I just wonder what express.static mean? I can't find an answer by searching Google.

This is just one example that I can't understand the code.

So is there any better documentation of express for the absolute beginner?

4

2 回答 2

6

我同意 Express 文档读起来更像一本书,而不是 API 文档。在 的情况下express.static,这是一个从 Connect ( ) 重新导出的中间件connect.static,Express 是基于该中间件构建的。从文档的中间件部分

通常使用连接中间件,您将需要('connect'),如下所示:

var connect = require('connect');
app.use(connect.logger());
app.use(connect.bodyParser());

这有点烦人,所以 express 重新导出了这些中间件属性,但是它们是相同的:

app.use(express.logger());
app.use(express.bodyParser());

您可以在他们的网站上看到中间件 Connect 公开的内容。特别是,请查看静态中间件的文档。

于 2012-06-18T03:00:36.237 回答
0

express并且static是该类的成员。什么express.static意思是“使用express类的静态方法”,该方法的作用是初始化一个静态文件服务器,由你的 node.js 服务器提供服务。static

于 2012-06-18T03:01:49.857 回答