Javascript 节点服务器重新启动自身

Javascript 节点服务器重新启动自身,javascript,node.js,Javascript,Node.js,所以我有一个文件“client.html”,它向节点服务器发送一个字符串 client.html <!DOCTYPE html> <html> <head> <title>Title</title> </head> <body> <form action="http://127.0.0.1:3000/search" method='get'> <input typ

所以我有一个文件“client.html”,它向节点服务器发送一个字符串

client.html

<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form action="http://127.0.0.1:3000/search" method='get'>
        <input type="text" name="name">
        <input type="submit" value="search">
    </form>
</body>
</html>

取而代之的是,“name”变量被打印出来,然后在一段时间后,在打印出“其他东西”之前,“name”变量再次被打印出来,就好像有人单击了客户端表单上的send按钮一样。需要一些帮助来修复此问题

我想您应该在连接超时和浏览器尝试重新连接之前回答客户端:

 app.get('/search', function(req, res) {
   var name = req.query.name;
   console.log(name);
   setTimeout(function(){
    console.log("Something else");
   }, 240000);

   res.end("Searching ...");
}) ;

如果我想在搜索完成后发回一些数据呢?我无法在console.log(“其他东西”)之后写入res.end(数据),因为res.end(“搜索…”)已执行before@bazzone240秒后你就不能了。每个连接都会超时。看看WebSocket,尤其是
 app.get('/search', function(req, res) {
   var name = req.query.name;
   console.log(name);
   setTimeout(function(){
    console.log("Something else");
   }, 240000);

   res.end("Searching ...");
}) ;