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

493
Views
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 answers
Answer question

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 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!