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

741
Views
Error [ERR_STREAM_WRITE_AFTER_END]: escribir después de finalizar, servidor http node.js

Configuración de un nuevo servidor http con Node.js

Cuando lo inicia por primera vez, muestra el texto html correcto en la pantalla, pero cuando pasa a otros enlaces en mi código, es decir: localhost:5001/about, me da un error en mi consola IDE.

 events.js:377 throw er; // Unhandled 'error' event ^ Error [ERR_STREAM_WRITE_AFTER_END]: write after end at new NodeError (internal/errors.js:322:7) at writeAfterEnd (_http_outgoing.js:694:15) at ServerResponse.end (_http_outgoing.js:815:7) at Server.<anonymous> (/Users/angelo/Documents/coding/node/node-tutorial/app.js:11:7) at Server.emit (events.js:400:28) at parserOnIncoming (_http_server.js:900:12) at HTTPParser.parserOnHeadersComplete (_http_common.js:127:17) Emitted 'error' event on ServerResponse instance at: at writeAfterEndNT (_http_outgoing.js:753:7) at processTicksAndRejections (internal/process/task_queues.js:83:21) { code: 'ERR_STREAM_WRITE_AFTER_END' } [nodemon] app crashed - waiting for file changes before starting...

aplicación.js

 const http = require('http'); const PORT = 5001; const server = http.createServer((req, res) => { if(req.url === '/'){ res.end('Home Page') } if(req.url === '/about'){ res.end('About Page') } res.end('Error page') }) server.listen(PORT, () => { console.log(`Server is listening on port: ${PORT}`) })

He estado buscando una respuesta para el error "escribir después del final", pero no he visto este problema específico para este bloque de código específico.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como se menciona en los comentarios, esto se debe a que se llama a res.end varias veces, la solución más simple para usted sería return después de cada res.end o ajustar sus condiciones:

 const http = require('http'); const PORT = 5001; const server = http.createServer((req, res) => { if(req.url === '/'){ res.end('Home Page') } else if(req.url === '/about'){ res.end('About Page') } else { res.end('Error page') } }) server.listen(PORT, () => { console.log(`Server is listening on port: ${PORT}`) })
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!