{"size": 1040, "ext": "js", "max_stars_repo_path": "demo/app.js", "max_stars_repo_name": "alykoshin/express-end", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "demo/app.js", "max_issues_repo_name": "alykoshin/express-end", "max_issues_repo_issues_event_min_datetime": "2022-01-22T08:31:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T08:31:32.000Z", "max_forks_repo_path": "demo/app.js", "max_forks_repo_name": "alykoshin/express-end", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 20.3921568627, "max_line_length": 94, "alphanum_fraction": 0.5990384615}
'use strict';

var express = require('express');
var http    = require('http');
//var endMw = require('express-end');
var endMw = require('../');
var app = express();

app.use(endMw);

var count = 0;

app.use(function(req, res, next) {
  var current = ++count;
  console.log('[%d] app.use()', current);

  res.once('close',  function() {
    console.log('[%d] app.use(): res.once(close)', current);
  });

  res.once('end',    function() {
    console.log('[%d] app.use(): res.once(end)', current);
  });

  res.once('finish', function() {
    console.log('[%d] app.use(): res.once(finish)', current);
  });

  next();
});


var httpPort = 8080;
var RESPONSE_DELAY = 1000; // Milliseconds

app.get('/test1', function (req, res) {
  var result = { test: 'test' };
  setTimeout(function() {
    res
      .status(200)
      .send(result);
  }, RESPONSE_DELAY);
});


var server = http.createServer(app);

server.listen(httpPort, function () {
  console.log('* Server listening at %s:%d', server.address().address, server.address().port);
});
