I want to print a string in Bulgarian in the console using nodejs. I have a index.js file which does:
console.log('Текст на български.');
When I run it in the console with: node index.js It prints only - '??????????' I am using Webstorm and I have set the IDE and Project File Encoding settings to utf8. I also tried:
var strInBulgarian = 'Текст на български.';
console.log(strInBulgarian.toString('utf8'));
The same result. If I run the following in nodejs REPL I get the correct result:
console.log('Текст на български.');
Which leads me to beleive that the reason I get '???????' is because of the file encoding, but it is set to utf8. Any ideas? Here is a screenshot from the settings in Webstorm.
Hmm now that I changed all of the settings to UTF8 the text that is in Bulgarian in my comments changed to '?????' and it was fine before that. Someting is definitely not right. When I make a index.js file from Notepad++ and set the encoding to utf8 I have no trouble there. Something is not right with the settings of Webstorm.
Webstorm's "Project Encoding" setting seems to only apply to newly added files. Judging from your screenshot (see lower-right corner), your individual files still use Windows-1252. You need to manually make Webstorm interpret each file as UTF-8.
Either through the dropdown menu on the bottom right of your window, after opening the file in question:
Or through the 'File Encodings' settings window itself:
Another possibility would be to directly mess with the .idea/encodings.xml
file in your project dir, but I won't go into details there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With