Defining and applying environments
Development and production code have different requirements. For instance, during development we will most likely want a detailed error output to the client, for debugging purposes. In production, we protect ourselves from opportunistic exploitation by revealing as little internal information as possible.
Express caters to these differences with app.configure
which allows us to define environments with specific settings.
Getting ready
We'll need our project folder (nca
) from the previous recipe.
How to do it...
Let's take a look at the preconfigured environments:
app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function(){ app.use(express.errorHandler()); });
The generated file defines customized error-reporting levels for each environment. Let's add caching to our production server, which can be a hindrance in development.
We use express.staticCache
to achieve...