nodejs中的setInterval

use*_*214 4 javascript setinterval node.js

我正在制作一个http请求,应该每隔一分钟运行一次.以下是我的代码

var express = require("express");
var app = express();
var recursive = function () {
    app.get('/', function (req, res) {
        console.log(req);
        //Some other function call in callabck
        res.send('hello world');
    });
    app.listen(8000);
    setTimeout(recursive, 100000);
}
recursive();
Run Code Online (Sandbox Code Playgroud)

根据上面的代码,我必须在每一分钟后得到答复.但我收到错误:听EADDRINUSE.任何有关这方面的帮助都会非常有帮助.

vp_*_*rth 7

此代码每分钟发出一次http请求:

var http = require('http');

var options = {
  host: 'example.com',
  port: 80,
  path: '/'
};
function request() {
  http.get(options, function(res){
    res.on('data', function(chunk){
       console.log(chunk);
    });
  }).on("error", function(e){
    console.log("Got error: " + e.message);
  });
}
setInterval(request, 60000);
Run Code Online (Sandbox Code Playgroud)