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

492
Vistas
TypeError: string.charCodeAt is not a function. How to encode object in node.js using express (restful api)

I use restful API with express & node.js and want to encode data to utf-8.

  1. I install utf8 with npm install utf8

  2. I set const utf8 = require('utf8');

  3. I use utf8.encode(string) to object like that:

     pool.query(`SELECT Station, Ime FROM auto_q_stations;`, function (error, result2, fields) {
    
    
     if (error)
         return res.status(500).json({ error: "Грешна заявка. Опитай отново !" })
       HQstationsAHS = result2;
       res.json({ HQstationsAHS })
     });
    

    });

I receive error like that:

TypeError: string.charCodeAt is not a function

How to encode object in node.js using express (restful api) ?

My problem is the following, when I execute a query in a database, all data in Bulgarian are OK.

When I execute the query in node.is & express environment I receive the data like that:

"������-��������"

Please help, I really don't know how to fix this problem.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You should loop through your array and change every "Ime" field. Something like

pool.query(`CALL Get_Discharge_Station('${dateNow}', ${daysBefore}, ${stNumber})`, function (error, result, fields) {
   if (error)
     return res.status(500).json({ error: "Грешна заявка. Опитай отново !" })

    HQstationsAHS = result2.map((item) => {
      item.Ime = utf8.encode(item.Ime);
      return item;
    });

   res.json({ HQstationsAHS })
 });
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