<commit_before>### Installation

    $ npm install express

or to access the `express(1)` executable install globally:

    $ npm install -g express

## Quick Start

 The quickest way to get started with express is to utilize the executable `express(1)` to generate an application as shown below:

 Create the app:

    $ npm install -g express
    $ express /tmp/foo && cd /tmp/foo

 Install dependencies:

    $ npm install -d

 Start the server:

    $ node app.js

### Creating A Server

 To create an instance of the _express.HTTPServer_, simply invoke the _createServer()_ method. With our instance _app_ we can then define routes based on the HTTP verbs, in this example _app.get()_.

    var app = require('express').createServer();
    
    app.get('/', function(req, res){
      res.send('hello world');
    });
    
    app.listen(3000);

### Creating An HTTPS Server

 To initialize a _express.HTTPSServer_ we do the same as above, however we
 pass an options object, accepting _key_, _cert_ and the others mentioned in node's [https documentation](http://nodejs.org/docs/v0.3.7/api/https.html#https.createServer).
 
     var app = require('express').createServer({ key: ... });

### Configuration

Express supports arbitrary environments, such as _production_ and _development_. Developers
can use the _configure()_ method to setup needs required by the current environment. When
_configure()_ is called without an environment name it will be run in _every_ environment 
prior to the environment specific callback.

In the example below we only _dumpExceptions_, and respond with exception stack traces
in _development_ mode, however for both environments we utilize _methodOverride_ and _bodyParser_.
Note the use of _app.router_, which can (optionally) be used to mount the application routes,
otherwise the first call to _app.get()_, _app.post()_, etc will mount the routes.

    app.configure(function(){
  		app.use(express.methodOverride());
  		app.use(express.bodyParser());
  		app.use(app.router);
  	});
	
  	app.configure('development', function(){
  		app.use(express.static(__dirname + '/public'));
  		app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
  	});
	
    app.configure('production', function(){
      var oneYear = 31557600000;
      app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
      app.use(express.errorHandler());
    });

For similar environments you may also pass several env strings:

    app.configure('stage', 'prod', function(){
      // config
    });

For internal and arbitrary settings Express provides the _set(key[, val])_, _enable(key)_, _disable(key)_ methods:

     app.configure(function(){
        app.set('views', __dirname + '/views');
        app.set('views');
        // => "/absolute/path/to/views"
        
        app.enable('some feature');
        // same as app.set('some feature', true);
        
        app.disable('some feature');
        // same as app.set('some feature', false);
     
        app.enabled('some feature')
        // => false
     });

To alter the environment we can set the _NODE_ENV_ environment variable, for example:

    $ NODE_ENV=production node app.js

This is _very_ important, as many caching mechanisms are _only enabled_ when in production.

### Settings

Express supports the following settings out of the box:

  * _home_ Application base path used for _res.redirect()_ and transparently handling mounted apps.
  * _views_ Root views directory defaulting to **CWD/views**
  * _view engine_ Default view engine name for views rendered without extensions
  * _view options_ An object specifying global view options
  * _view cache_ Enable view caching (enabled in production)
  * _case sensitive routes_ Enable case-sensitive routing
  * _strict routing_ When enabled trailing slashes are no longer ignored
  * _jsonp callback_ Enable _res.send()_ / _res.json()_ transparent jsonp support

### Routing

Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.
For example we may want to render a user's account for the path _/user/12_, this
can be done by defining the route below. The values associated to the named placeholders 
are available as `req.params`.

    app.get('/user/:id', function(req, res){
  		res.send('user ' + req.params.id);
  	});

A route is simple a string which is compiled to a _RegExp_ internally. For example
when _/user/:id_ is compiled, a simplified version of the regexp may look similar to:<commit_msg>docs for previous commit<commit_after>### Installation

    $ npm install express

or to access the `express(1)` executable install globally:

    $ npm install -g express

## Quick Start

 The quickest way to get started with express is to utilize the executable `express(1)` to generate an application as shown below:

 Create the app:

    $ npm install -g express
    $ express /tmp/foo && cd /tmp/foo

 Install dependencies:

    $ npm install -d

 Start the server:

    $ node app.js

### Creating A Server

 To create an instance of the _express.HTTPServer_, simply invoke the _createServer()_ method. With our instance _app_ we can then define routes based on the HTTP verbs, in this example _app.get()_.

    var app = require('express').createServer();
    
    app.get('/', function(req, res){
      res.send('hello world');
    });
    
    app.listen(3000);

### Creating An HTTPS Server

 To initialize a _express.HTTPSServer_ we do the same as above, however we
 pass an options object, accepting _key_, _cert_ and the others mentioned in node's [https documentation](http://nodejs.org/docs/v0.3.7/api/https.html#https.createServer).
 
     var app = require('express').createServer({ key: ... });

### Configuration

Express supports arbitrary environments, such as _production_ and _development_. Developers
can use the _configure()_ method to setup needs required by the current environment. When
_configure()_ is called without an environment name it will be run in _every_ environment 
prior to the environment specific callback.

In the example below we only _dumpExceptions_, and respond with exception stack traces
in _development_ mode, however for both environments we utilize _methodOverride_ and _bodyParser_.
Note the use of _app.router_, which can (optionally) be used to mount the application routes,
otherwise the first call to _app.get()_, _app.post()_, etc will mount the routes.

    app.configure(function(){
  		app.use(express.methodOverride());
  		app.use(express.bodyParser());
  		app.use(app.router);
  	});
	
  	app.configure('development', function(){
  		app.use(express.static(__dirname + '/public'));
  		app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
  	});
	
    app.configure('production', function(){
      var oneYear = 31557600000;
      app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
      app.use(express.errorHandler());
    });

For similar environments you may also pass several env strings:

    app.configure('stage', 'prod', function(){
      // config
    });

For internal and arbitrary settings Express provides the _set(key[, val])_, _enable(key)_, _disable(key)_ methods:

     app.configure(function(){
        app.set('views', __dirname + '/views');
        app.set('views');
        // => "/absolute/path/to/views"
        
        app.enable('some feature');
        // same as app.set('some feature', true);
        
        app.disable('some feature');
        // same as app.set('some feature', false);
     
        app.enabled('some feature')
        // => false
     });

To alter the environment we can set the _NODE_ENV_ environment variable, for example:

    $ NODE_ENV=production node app.js

This is _very_ important, as many caching mechanisms are _only enabled_ when in production.

### Settings

Express supports the following settings out of the box:

  * _home_ Application base path used for _res.redirect()_ and transparently handling mounted apps.
  * _views_ Root views directory defaulting to **CWD/views**
  * _view engine_ Default view engine name for views rendered without extensions
  * _view options_ An object specifying global view options
  * _view cache_ Enable view caching (enabled in production)
  * _charset_ Alter the default charset of "utf-8"
  * _case sensitive routes_ Enable case-sensitive routing
  * _strict routing_ When enabled trailing slashes are no longer ignored
  * _jsonp callback_ Enable _res.send()_ / _res.json()_ transparent jsonp support

### Routing

Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.
For example we may want to render a user's account for the path _/user/12_, this
can be done by defining the route below. The values associated to the named placeholders 
are available as `req.params`.

    app.get('/user/:id', function(req, res){
  		res.send('user ' + req.params.id);
  	});

A route is simple a string which is compiled to a _RegExp_ internally. For example
when _/user/:id_ is compiled, a simplified version of the regexp may look similar to:
{'fraction_non_alphanumeric': 0.09555261999119331, 'fraction_numerical': 0.004953764861294584, 'mean_word_length': 3.6140172676485527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4387978', 'n_tokens_mistral': 2533, 'n_tokens_neox': 2402, 'n_words': 1007}