I have a very basic node script that starts up, serving up an html page and finally closes the app (kills the node process ideally). Everything works great except the last line that invokes the close method to tear it down.
var express = require('express')
, http = require('http')
, app = express()
, server = http.createServer(app);
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
});
app.listen(8090);
console.log("started...");
app.close();
The error I get when I run this w/ node 0.8+ is
app.close();
^
TypeError: Object function app(req, res){ app.handle(req, res); } has no method 'close'
Anyone know how I can more safely close the express app down?
So far the best approach I've found it to kill the node process. seems to get the job done (although for purity I'd like to just close express)
process.exit(code=0)
You were so close:
var express = require('express')
, http = require('http')
, app = express()
, server = http.createServer(app);
app.get('/', function(req, res) {
res.sendfile(__dirname + '/index.html');
});
var listener = app.listen(8090);
console.log("started...");
listener.close();
process.on('SIGTERM', function () {
app.close();
});
Try that