Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
No puedo iniciar mi servidor websocket localhost

Estoy tratando de crear un servidor websocket localhost con el nodo 16.13 y no sé por qué, pero parece que nada funciona. No puedo iniciar mi index.js con el nodo index.js, recibo este mensaje de error -> Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.(Use node --trace-warnings ... to show where the warning was created)

Además, este mensaje en el navegador Access to script at 'file:///.../server/index.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

En mi archivo html he usado <script type="module" src="./server/index.js"></script>

 (index.js file) import WebSocket from 'ws'; const wss = new WebSocket.Server({ port: 8080}); const ws = new WebSocket("ws://localhost:8080"); ws.addEventListener("open", () => { console.log("We're connected") ws.send("Hey, how is going?"); }); ws.on("connection", ws => { console.log("New client Connected"); ws.on("message", data => { console.log(`Client has sent Us: ${data}`); }); }); ws.on("close", () => { console.log("client has disconnected"); });```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Está importando su módulo con sintaxis ESM y nodejs solo admite CommonJs

Cambio

 import WebSocket from 'ws';

Para:

 const ws = required('ws')
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!