0

I am really new in vanilla node.js servers. I know there are easier methods to create your own server (like epxress), but I wanted to create a server from the very basics so I'm not that experienced in this area.

I use two methods: the .find and .filter. With the .find method the text is nice, but with the .filter method it looks like the utf-8 charset is just not working.

It writes it correctly:

res.setHeader("Content-type", "text/plain; charset=utf-8");
res.write(JSON.stringify(myfile.find((i) => i.id == id), null, 4));
{
    "id": "A0Eu3M6VXuprBxg",
    "type": "fact",
    "text": "A Minecraft első verziója (akkoriban még Cave Game) hat nap alatt készült el."
}

It writes it wrong:

res.setHeader("Content-type", "text/plain; charset=utf-8");
res.write(JSON.stringify(myfile.filter((i) => i.type == type), null, 4));
[
    {
        "id": "A0Eu3M6VXuprBxg",
        "tipus": "teny",
        "szoveg": "A Minecraft elsĹ verziĂłja (akkoriban mĂŠg Cave Game) hat nap alatt kĂŠszĂźlt el."
    },
    {
        "id": "1AKm3NQ8w1329pB",
        "tipus": "teny",
        "szoveg": "A Ghastok hangjai egy alvĂł macskĂĄtĂłl szĂĄrmaznak. NĂŠvszerint a Minecraft hangproducere, Daniel 'C418' Rosenfeld macskĂĄjĂĄtĂłl, aki azt vĂŠletlenĂźl rĂśgzĂ­tette felkelĂŠskor."
    }
]
RolandHU
  • 3
  • 2

0 Answers0