Nodejs web server goes idle when not in direct use

  • Greetings

    Using nodejs, I am running a generic express https web server that is serving to my local network. Running on a windows 10 machine, the server is able to make connections with all devices on my lan without any problems. That is until a couple minutes pass by and the server seemingly goes idle, ceasing to responding to any requests made by any devices. Hitting enter in the console fixes this problem but is not preferable. Is there a way to keep node running at all times? I am sadly not able to switch to a different os, if this is some sort of windows task focusing feature then I would presumably be out of luck.

    Server.js:

    Code
    @@@WCF_PRE_LINEBREAK@@@const express = require("express");  @@@WCF_PRE_LINEBREAK@@@const https = require("https");  @@@WCF_PRE_LINEBREAK@@@const path = require("path");  @@@WCF_PRE_LINEBREAK@@@const fs = require("fs");  @@@WCF_PRE_LINEBREAK@@@const ip = require("ip");  @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@const app = express();  @@@WCF_PRE_LINEBREAK@@@const port = 443;  @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@//determines what folder houses js, css, html, etc files - console.log the ip of a connected client   @@@WCF_PRE_LINEBREAK@@@app.use(express.static(__dirname + "/public/"), function (req, res, next) {  @@@WCF_PRE_LINEBREAK@@@  const ip = req.ip;  @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@  console.log("Now serving ip:", "\x1b[33m", ip, "\x1b[37m");  @@@WCF_PRE_LINEBREAK@@@  next();  @@@WCF_PRE_LINEBREAK@@@});  @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@//determines which file is the index  @@@WCF_PRE_LINEBREAK@@@app.get("/", function (req, res) {  @@@WCF_PRE_LINEBREAK@@@  res.sendFile(path.join(__dirname + "/public/index.html"));  @@@WCF_PRE_LINEBREAK@@@});  @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@var sslServer = https.createServer(  @@@WCF_PRE_LINEBREAK@@@  {  @@@WCF_PRE_LINEBREAK@@@    key: fs.readFileSync(path.join(__dirname, "certificate", "key.pem")),  @@@WCF_PRE_LINEBREAK@@@    cert: fs.readFileSync(  @@@WCF_PRE_LINEBREAK@@@      path.join(__dirname, "certificate", "certificate.pem")  @@@WCF_PRE_LINEBREAK@@@    ),  @@@WCF_PRE_LINEBREAK@@@  },  @@@WCF_PRE_LINEBREAK@@@  app  @@@WCF_PRE_LINEBREAK@@@);  @@@WCF_PRE_LINEBREAK@@@@@@WCF_PRE_LINEBREAK@@@//determines which port server should listen on - console.log when server has successfully started  @@@WCF_PRE_LINEBREAK@@@sslServer.listen(port, function () {  @@@WCF_PRE_LINEBREAK@@@  console.log(  @@@WCF_PRE_LINEBREAK@@@    "Server has successfully started, available on:",  @@@WCF_PRE_LINEBREAK@@@    "\x1b[33m",  @@@WCF_PRE_LINEBREAK@@@    ip.address(),  @@@WCF_PRE_LINEBREAK@@@    "\x1b[37m",  @@@WCF_PRE_LINEBREAK@@@    "listening on port:",  @@@WCF_PRE_LINEBREAK@@@    "\x1b[33m",  @@@WCF_PRE_LINEBREAK@@@    +port,  @@@WCF_PRE_LINEBREAK@@@    "\x1b[37m"  @@@WCF_PRE_LINEBREAK@@@  );  @@@WCF_PRE_LINEBREAK@@@  console.log("CTRL + C to exit server");  @@@WCF_PRE_LINEBREAK@@@});  

    Will provide any needed information.

  • wild1145 November 2, 2022 at 6:41 PM

    Selected a post as the best answer.