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?
I agree that the Express documentation reads a bit more like a book than an API doc. In the case of express.static
, this is a re-expored middleware from Connect (connect.static
), which Express is built on. From the middleware section of the docs:
Typically with connect middleware you would require(‘connect’) like so:
var connect = require('connect'); app.use(connect.logger()); app.use(connect.bodyParser());
This is somewhat annoying, so express re-exports these middleware properties, however they are identical:
app.use(express.logger()); app.use(express.bodyParser());
You can see what middleware Connect exposes on their web site. In particular, check out the documentation for the static middleware.
express
is the class and static
is a member of that class. What express.static
means is "use the static method of the express class", what the static
method does is initialize a static file server to be served by your node.js server.