I am trying to create an instance of a javascript class but i keep getting the error:
TypeError: Server is not a function
Not sure how to get this to work correctly. My class looks like this:
server.js
class Server {
#app;
#port;
constructor(port) {
this.#port = port;
this.#app = require('express')();
}
setStaticDirectory(directory) {
this.app.use(express.static(directory));
}
init() {
console.log(this.#app.listenerCount);
this.#app.listen(port);
}
}
And then in my main file i have:
main.js
var Server = require("./server.js");
const PORT = 3000;
const STATICS = 'public';
const SERVER = new Server(PORT); // error is here
SERVER.setStaticDirectory(STATICS);
SERVER.init();
What am i missing here? I come from a C# background so i am a bit confused why i get this error.