punund punund - 5 months ago 30
Node.js Question

access to HTTP server object in node.js express

I am inside a middleware (

function(req, res, next) {...}

Is there a way to access the HTTP server object from the


Let me be more specific. I am trying to find out a port that the server listens on, or unix socket path, if it's listening on that.


How about in your main app file:

var express = require('express');
var http = require('http');
var app = express();


app.get('/', function (req, res, next) {

app.server = http.createServer(app);

As Brad mentioned, Express does expose something resembling the object returned from #createServer(), however, TJ has been giving serious consideration to dropping any inclusion of the HTTP module in express in future releases. Using the code above will be future safe.