使用app.get后释放资源

我使用express()。从node.js获取特定path的GET请求。 但是,在某个时候,我希望不再继续在这条路上提供GET请求。 我如何:

  1. 停止服务器接受该path的GET请求。
  2. 释放我累积的所有资源。

所以这是一个简化版本的问题。

var express = require("express"); var app = express(); var http = require("http").Server(app); app.get("/", function(req, res) { // do some stuff // ... // check if we should stop serving requests here setInterval(function() { if (shouldBeClosed) { // what should be here? } }, 1000); }); http.listen(8080, function() { }); 

你可以简单地开始返回一个404或其他错误代码…

 var stop = false; app.get("/", function(req, res) { if (!stop) { // do some stuff // ... // check if we should stop serving requests here setInterval(function() { if (shouldBeClosed) { stop = true; } }, 1000); } else { res.status(404).send('nothing is here any more!'); } }); 

至于第二个问题:你是指什么样的资源?