javascriptnode.jssocket.iorequirejsrequire

Issue in converting all "import * from" to "const * = req() in Nodejs


There is import function: import socketIO, { Server as SocketIOServer } from "socket.io";

i want to convert this to const socketIO, { Server as SocketIOServer } = require("socket.io")

But it is not working, what would by type format in require?

`

error: TS1005',' expected


Solution

  • It is solved with the following code:

    const { Server: SocketIOServer, default: socketIO  } = require("socket.io")