I use node-cron
to run the program at regular basis. I run the following code, but I got the error below that says the port is already in use.
I run node.js programs from command prompt in windows 10. Once I got this error, I closed the command prompt window in aim to end all the connection in use. And opened the window again and run the node program again. But I got the same error.
I should have used the port number 3128 only by this program. This program has been with no problem so far as I have run it multiple times. But suddenly this error started to occur today.
I want to know why the port is still in use even after the program ends, and want to know if node-cron program should be closed explicitly with some codes something like node-cron.closePort()
?
sched_exec.js
"use strict";
const cron = require("node-cron");
const express = require("express");
const fs = require("fs");
const sync_module = require('./sync');
const logwriter = require('./logWriter/logwriter');
const app = express();
// schedule tasks to be run on the server
//const exec_timing = "0 2 * * *";
const exec_timing = "* * * * *";
cron.schedule(exec_timing, function() {
logwriter.info("start");
//do something
});
app.listen(3128);
The error:
C:\inetpub\ftpfolder\syncSchedule>node sched_exec
events.js:292
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3128
at Server.setupListenHandle [as _listen2] (net.js:1313:16)
at listenInCluster (net.js:1361:12)
at Server.listen (net.js:1447:7)
at Function.listen (C:\inetpub\ftpfolder\syncSchedule\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (C:\inetpub\ftpfolder\syncSchedule\sched_exec.js:21:5)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1340:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'EADDRINUSE',
errno: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 3128
}
I did netstat -ab. It says, [node.exe] is the owner of the connection of the port 3128. however, I don't suppose any other node process is running.
I also have done research on task manage.
It has two node.js processes. But I don't know why. Should I ask this in another post?