EADDR in use, function running on setInterval

Hi,

I have a project that runs a series of functions every 5 minutes using setInterval. One of the functions creates a server that listens on port 8080. So on each 5 minute interval, I get the “EADDR in use” error. I want to refresh the content on each interval, but maybe it’s not necessary to create the server each time. That or else I could set the listener to time out. But it doesn’t seem to work. Any ideas?

function WriteHTML() {
var server = http
.createServer(function(req, res) {
res.writeHead(200, { “Content-Type”: “text/html” });
res.write("<href=%22/style.css%22>");
res.write(makeTableHTML(item, objlen + 2, i, j));
res.write(makeTableHTML(itemapi, length + 3, k, m));
res.write("");
res.end();
})

.listen(8080);

server.timeout = 250000;
}

Here is the project:
https://kcbtcinterval.glitch.me/

Thanks much!
Kevin G

@kevingallagher34, you’re attempting to listen to port 8080 according to the code, but Glitch accepts only port: 3000. So changing .listen(8080) to .listen(3000) might work.

1 Like

Hi @khalby786,

I changed my port to 3000. However, it doesn’t appear to have resolved the issue. Any other suggestions?

Thanks so much for your help!

Kevin G