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

338
Vistas
How to get the data from res.on in Nodejs

I use the GET method to request api,but now I want to return chunk as the value of that method. How I can write to get the global 'chunk' value?

res.on('data', (chunk) => {
            console.log('body:${chunk}`);
        
        })
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This is my function, I want to return the chunk that includes the WeChat minapp user's openid information, and I can use the openid to judge if the user has register or use the openid to get more information.

function getWXOpenId(body) {

    //bode:minapp post value;
    //console.log(body);
    var params = new URLSearchParams(body);
    //https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code
    var wx_appid = '';
    var wx_secret = '';
    var wx_tempCode = params.get("code");
    var wx_url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + wx_appid + '&secret=' + wx_secret + '&js_code=' + wx_tempCode + '&grant_type=authorization_code';
    var req = https.request(wx_url, function (res) {
        console.log('statusCode' + res.statusCode);
        res.setEncoding('utf8');
        res.on('data', (chunk) => {
             //the chunk has the openid value
            console.log(`body: ${chunk}`);

        })
        res.on('end', () => {
            console.log('end');
        });
    });
    req.on('error', (e) => {
        console.error('error' + e.message);
        return ;
    });
    //end
    req.end();
}

Now I want return the trunk value to get the openid.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you mean how to get the chunks on client-side, I suggest to use axios and configure the option onDownloadProgress, which allows handling of progress events for downloads.

Please, bear in mind that it only works for browsers, if you intend to work with other clients (e.g. API), that will not work.

about 4 years ago · Juan Pablo Isaza Denunciar
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