This week I tried upgrade the "HTTP server with ngrok from my local host" to "HTTPS server host on my VPS server" and create database and data log for my project.

Here is the code I used to create the database.

var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('my-key.pem'),
  cert: fs.readFileSync('my-cert.pem')
};

app.use(express.static("public"));

const http = https.createServer(options, app);

const port = process.env.PORT || 8080;

const server = http.listen(port);

/////Database////////
var usermessages = [];
var Datastore = require('nedb');
var db = new Datastore({ filename: "feizaiData.db", autoload: true });

db.find({}, function (err, docs) {
  for (let i = 0; i < docs.length; i++) {
    usermessages.push(docs[i].message);
  }
});

let clients = {};

main();

function main() {
  setupSocketServer();

  setInterval(function () {
    io.sockets.emit("userPositions", clients);
  }, 100);
}

function setupSocketServer() {

  io.on("connection", (client) => {
    // Get Date
    let today = new Date();
    let date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate() + ' ' + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();

    let datalog =
      "User " +
      client.id +
      " connected, there are " +
      io.engine.clientsCount +
      " clients connected" + " at " + date;

    console.log(datalog);

    db.insert({ "message": datalog }, function (err, newDocs) {
      console.log("err:" + err);
      console.log("newDocs:" + newDocs);
    });

}

When I run that from local host, it worked and gave me a database like below.

feizaiData.db

{"message":"User vxg2lzfNk3aF7gL5AAAB connected, there are 1 clients connected at 2021-4-22 1:2:55","_id":"6TVYv3I5axEIdQLa"}
{"message":"User qyzGqDcpWJRLpJ4iAAAB connected, there are 1 clients connectedat 2021-4-22 1:2:13","_id":"TmRWDRMy5q95bhma"}
{"message":"User spsmAsxS7i6wH9LxAAAD connected, there are 1 clients connected at 2021-4-22 1:2:59","_id":"i3wN05q9ZOjmzXF0"}
{"message":"User S-6EH0buxhjWjZhRAAAA connected, there are 1 clients connected at 2021-4-27 11:47:49","_id":"nN0QNBVioYj7dUZY"}
{"message":"User zCH9HkNRFtSfRmmgAAAB connected, there are 2 clients connected at 2021-4-27 11:47:50","_id":"cpufRsEy0oBdR1tT"}
{"message":"User 8ud54tjYL_9uq1XDAAAC connected, there are 3 clients connected at 2021-4-27 11:47:54","_id":"YuWgC4iufKrN0Zka"}
{"message":"User ewosrFiU-kIUB26IAAAD connected, there are 4 clients connected at 2021-4-27 11:47:58","_id":"PlnmR68A4sX1kFNC"}
{"message":"User sMjlIJ0d2zDpGQwRAAAE connected, there are 5 clients connected at 2021-4-27 11:48:6","_id":"rlGq1btJJxDflFjx"}
{"message":"User yKMpyVyRa0XCsoBTAAAF connected, there are 6 clients connected at 2021-4-27 11:48:16","_id":"jNGYL13EbXsp47SS"}
{"message":"User 5ZG_1uExAYFycbVSAAAG connected, there are 4 clients connected at 2021-4-27 11:48:24","_id":"FwIfmRIn1f2JeWSA"}
{"message":"User 82EdyxLkTogWV4raAAAH connected, there are 4 clients connected at 2021-4-27 11:48:32","_id":"ZfHVcuGt7vXQi4Iw"}
{"message":"User 3YMMUgLJB5YbSmpPAAAI connected, there are 4 clients connected at 2021-4-27 11:48:39","_id":"nofYU8OXBPiOCTjJ"}
{"message":"User 5Lnd_DoXpIMcJfiPAAAJ connected, there are 4 clients connected at 2021-4-27 11:48:46","_id":"X4YUBkMJ7BMneox9"}
{"message":"User y24WBUyrGhg22pETAAAK connected, there are 4 clients connected at 2021-4-27 11:48:59","_id":"EElTjrjpmPyzBYr6"}
{"message":"User FJrqQlQOldw1k2BzAAAL connected, there are 5 clients connected at 2021-4-27 11:49:0","_id":"V0zIQ1osAS0iietN"}
{"message":"User uEjhaRv73exNgZsQAAAM connected, there are 5 clients connected at 2021-4-27 11:49:3","_id":"68NXSbw5O3yQLTh4"}
{"message":"User uhxYFC5Ujl96yObZAAAN connected, there are 6 clients connected at 2021-4-27 11:49:7","_id":"T7fA7dbRIFDhawZA"}
{"message":"User HKspEBKzrrUVrZ1jAAAO connected, there are 6 clients connected at 2021-4-27 11:49:14","_id":"Efj7ps6EKgzmhj9J"}
{"message":"User vAMZwcacygqaCj85AAAP connected, there are 6 clients connected at 2021-4-27 11:49:21","_id":"eBWrpE3T1Fix4F7U"}
{"message":"User SeB51IPEzLt4yPHxAAAQ connected, there are 7 clients connected at 2021-4-27 11:49:28","_id":"ZOkeriKCgt10CMpR"}
{"message":"User tFZQKTWqKrw_QobJAAAR connected, there are 4 clients connected at 2021-4-27 11:49:39","_id":"uUUEyD0NbobunjLK"}
{"message":"User L6Rc1pkAcRsGkiiiAAAS connected, there are 4 clients connected at 2021-4-27 11:49:46","_id":"WSFx9OfZvx6eMxSX"}
{"message":"User P_ORKCb1QhfgVgqAAAAT connected, there are 4 clients connected at 2021-4-27 11:49:55","_id":"RVkRXoUA8b2AYvSe"}
{"message":"User BwUnHZdyfc5wDD0cAAAU connected, there are 4 clients connected at 2021-4-27 11:50:2","_id":"4gqijs3VjTnGs232"}
{"message":"User 7fgjhQrXiJhlwrNqAAAV connected, there are 5 clients connected at 2021-4-27 11:50:9","_id":"7WKCycezZN3m3v7q"}
{"message":"User kn7J519p3hmjudGKAAAW connected, there are 1 clients connected at 2021-4-27 11:50:40","_id":"X2p4yUF5vX3Vmq16"}
{"message":"User eHqI66ngutU3CDGoAAAX connected, there are 2 clients connected at 2021-4-27 11:50:41","_id":"cUJpiL8RUcDFt3Pb"}
{"message":"User 6-WF6WRewsPOSAAAAAAY connected, there are 3 clients connected at 2021-4-27 11:50:43","_id":"htg7qWuKa31E6cwy"}
{"message":"User mm4Zk5KJ8m6zlsGIAAAZ connected, there are 4 clients connected at 2021-4-27 11:50:46","_id":"hqtPfSkZ8dZKOZIL"}
{"message":"User VtfkNZGu9RyJnQ7IAAAa connected, there are 5 clients connected at 2021-4-27 11:50:54","_id":"LwfmIcfo4SRXWMIy"}
{"message":"User 1ytggWbjYftO1oV1AAAb connected, there are 6 clients connected at 2021-4-27 11:51:1","_id":"Hg5QQBTytKR1GoTv"}
{"message":"User D1bNtyC-hkUDR2ECAAAc connected, there are 7 clients connected at 2021-4-27 11:51:9","_id":"MQZZVUZk5H19fMOy"}
{"message":"User 0Db_kiJrNreC785aAAAd connected, there are 4 clients connected at 2021-4-27 11:51:18","_id":"hiYUXh3KRQe7Wt7J"}
{"message":"User Pb6N3kydVwsyiADxAAAe connected, there are 4 clients connected at 2021-4-27 11:51:26","_id":"jqhHD10bOF69SUfj"}

It gives me the information every time when new users connected, about their socket_id, the time they get connected, how many users are connected at the same time.

When I tried to upload the project to the VPS, some errors came. I uploaded everything except the node modules, and did "npm install". Unfortunately it didn't give me all the modules but throw out errors.

npm-debug.log