• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

151
Vistas
How to stream a data stream to client from Node.js server

My Node.js server receives a stream of data from an external API. I serve my client after receiving the data completely. Like this,

async function getFile(req, res) {
    const { id } = req.body;
    const file = await get(process.env.FILE_API_URL + id);

    res.send(file);
}

But instead of waiting to receive the whole stream, I would like to stream it to the client as soon as I have some data. Kind of like this,

function getFile(req, res) {
    const { id } = req.body;
    const stream = get(process.env.FILE_API_URL + id);

    stream.on('data', (data) > {
        res.write(data);
    });

    stream.on('end', res.end);
}

How can I implement this?

about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda