generators/app/templates/server/config/express.js
function initExpress(app) {
  var env = app.get('env');
  var publicDir = path.join(config.root, config.publicDir);

  app.set('ip', config.ip);
  app.set('port', config.port);

  app.set('views', config.root + '/server/views');
  app.engine('html', require('ejs').renderFile);
  app.set('view engine', 'html');

  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(passport.initialize());
  app.use(favicon(path.join(publicDir, 'favicon.ico')));

  if ('production' === env) {
    app.use(express.static(publicDir));
    app.set('appPath', publicDir);
    app.use(morgan('tiny'));
  }

  if ('development' === env || 'test' === env) {
    app.use(express.static(path.join(config.root, '.tmp')));
    app.use(express.static(publicDir));
    app.set('appPath', publicDir);
    app.use(morgan('dev'));
    // Error handler - has to be last
    app.use(errorHandler());
  }
}
function initExpress(app) {
  var env = app.get('env');
  var publicDir = path.join(config.root, config.publicDir);

  app.set('ip', config.ip);
  app.set('port', config.port);

  app.set('views', config.root + '/server/views');
  app.engine('html', require('ejs').renderFile);
  app.set('view engine', 'html');

  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(passport.initialize());
  app.use(favicon(path.join(publicDir, 'favicon.ico')));

  if ('production' === env) {
    app.use(express.static(publicDir));
    app.set('appPath', publicDir);
    app.use(morgan('tiny'));
  }

  if ('development' === env || 'test' === env) {
    app.use(express.static(path.join(config.root, '.tmp')));
    app.use(express.static(publicDir));
    app.set('appPath', publicDir);
    app.use(morgan('dev'));
    // Error handler - has to be last
    app.use(errorHandler());
  }
}
function initExpress ( app ) { var env = app . get ( 'env' ) ; var publicDir = path . join ( config . root , config . publicDir ) ; app . set ( 'ip' , config . ip ) ; app . set ( 'port' , config . port ) ; app . set ( 'views' , config . root + '/server/views' ) ; app . engine ( 'html' , require ( 'ejs' ) . renderFile ) ; app . set ( 'view engine' , 'html' ) ; app . use ( compression ( ) ) ; app . use ( bodyParser . urlencoded ( { extended : false } ) ) ; app . use ( bodyParser . json ( ) ) ; app . use ( methodOverride ( ) ) ; app . use ( cookieParser ( ) ) ; app . use ( passport . initialize ( ) ) ; app . use ( favicon ( path . join ( publicDir , 'favicon.ico' ) ) ) ; if ( 'production' === env ) { app . use ( express . static ( publicDir ) ) ; app . set ( 'appPath' , publicDir ) ; app . use ( morgan ( 'tiny' ) ) ; } if ( 'development' === env || 'test' === env ) { app . use ( express . static ( path . join ( config . root , '.tmp' ) ) ) ; app . use ( express . static ( publicDir ) ) ; app . set ( 'appPath' , publicDir ) ; app . use ( morgan ( 'dev' ) ) ; // Error handler - has to be last app . use ( errorHandler ( ) ) ; } }
Configure the express application by adding middleware and setting application
variables.
@param {express.app} app - The express application instance to configure
Configure the express application by adding middleware and setting application variables .