I'm using Express 3.0 alpha to build an app but am a little confused with the app config structure
app.configure ->
app.set "views", __dirname + "/views"
app.set "view engine", "jade"
app.use express.bodyParser()
app.use express.methodOverride()
app.configure "development", ->
app.use express.logger("dev")
app.configure "production", ->
app.use express.logger()
Is the first app.configure, ->
required? I've been browsing other people's apps and it doesn't seem to matter if I use it.
How does ordering work for app.configure, ->
? It seems correct to put the specific environments (development, and production) after the first app.configure, ->
as I've seen in other apps but it doesn't seem to work with my app (i.e. the logger doesn't print anything in my console at all).
Thanks in advance!
The app. use() method mounts or puts the specified middleware functions at the specified path. This middleware function will be executed only when the base of the requested path matches the defined path.
They're just executed in sequence. The first will be invoked for all environments, so it doesn't matter if it's wrapped with configure()
at all; it just looks nicer. But if you look at the Express issue queue, they'll likely be disappearing in the future since they're effectively just glorified if statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With