Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Converting ws to an ES6 import

I'm converting an application to ES6 imports instead of CommonJS requires, and I'm having trouble with the ws package.

Here's the old code:

const { createServer } = require('http');
const ws = require('ws');
const server = createServer();
server.listen(123);

const wsServer = new ws.Server({
   server
});

wsServer.on('connection', (socket) => {
//...

Here's the new code:

import wsPackage from 'ws';
const { Server } = wsPackage;

const wsServer = new Server({
    server
});

let connections = [];

wsServer.on('connection', (socket) => {
//...

But I get an error when using the Server constructor:

TypeError: Server is not a constructor

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda