title: Extremely Long TTFB on localhost (Node/Express)
body: <p>I'm experiencing extremely long TTFB on my <strong>localhost</strong> node/express server.</p>
  
  <p><strong>On average each request's(including static resource) TTFB is around 1s, occasionally up to 7s(I guess this is NOT normal)</strong></p>
  
  <p><strong>What could cause this long TTFB and how to improve?</strong></p>
  
  <p>Could it be my fault for configing express wrong?</p>
  
  <p>Here is my app.js:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var express = require('express');
  var path = require('path');
  var bodyParser = require('body-parser');
  var methodOverride = require('method-override');
  var favicon = require('serve-favicon');
  var morgan = require('morgan')
  
  
  //Router files
  var all = require('./api/all');
  var admin = require('./api/admin');
  var student = require('./api/student');
  var teacher = require('./api/teacher');
  var course = require('./api/course');
  var forum = require('./api/forum');
  var group = require('./api/group');
  var board = require('./api/board');
  
  // App Setup
  var app = express();
  // View engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  
  app.use(morgan(':remote-addr [:date[clf]] :user :method :url :status :response-time ms',{
    skip: function (req, res) {
        //var noUser = (req.AV.user === undefined);
        //return noUser;
        return true;
    }
  }));
  
  app.use(favicon(__dirname + '/public/favicon.ico'));
  
  
  // Load Cloud Code
  //app.use(cloud);
  
  
  //Express Middleware
  app.use(methodOverride('_method'))
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  
  
  
  app.use(express.static(__dirname+'/public'));
  //The Route
  app.get('/', function(req, res) {
      res.send('./public/index.html');
  });
  
  //Routers
  app.use('/api',all);
  app.use('/api/admin',admin);
  app.use('/api/student',student);
  app.use('/api/teacher',teacher);
  app.use('/api/course',course);
  app.use('/api/forum',forum);
  app.use('/api/group',group);
  app.use('/api/board',board);
  
  
  
  //404 Handler
  app.use(function(req, res, next) {
      //console.log("NOT FOUND: "+req.url);
      var err = new Error('Not Found');
      err.status = 404;
      res.render('notfound.jade');
      //next(err);
  });
  // error handlers for different env
  if (app.get('env') === 'development') {
      console.log("dev env");
      app.use(function(err, req, res, next) {
          res.status(err.status || 500);
          if(res.status===500){
              console.log(err);
              //console.log(err.stack.split("\n"));
          }
          res.send({
              message: err.message,
              error: err
          });
      });
  }
  app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      console.log(err.message);
      res.send({
          message: err.message,
          error: {}
      });
  });
  
  module.exports = app;</code></pre>
  </div>
  </div>
  </p>
  
  <p>ps:I'm using node 4.0.0 and latest chrome</p>