Hi i want to organise my code a little better and want to split all my socket.on() events into multiple files.
Right now this is my setup. Everything is in index.mjs.
io.on('connection', function (socket) {
socket.on('event1', function (member) {
// do smth
});
socket.on('event2', function (member) {
// do smth
});
});
What i want to do is something like this
io.on('connection', function (socket) {
require("./events/1.mjs");
require("./events/2.mjs");
});
But i get the following error:
require() of ES Module ./events/1.mjs not supported.
Instead change the require of ./events/1.mjs to a dynamic import() which is available in all CommonJS modules.
I tried to somehow use the import statement but i honestly dont know how the ./events/1.mjs file would need to look like. I tried googling and other posts and forums but couldnt get it to work which is frustrating