6

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. enter image description here

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.

4
  • Have you tested it using a normal console instead of Webstorm? Commented Jul 4, 2015 at 13:00
  • I am using the default windows command prompt not a console from Webstorm. I am just writing my code in Webstorm. Commented Jul 4, 2015 at 13:03
  • Did you try clicking on the Default Encoding field for your js file and explicitly setting it to UTF8? Or try the File->File encoding menu and changing the open file to UTF8 to convert the file? Commented Jul 4, 2015 at 15:29
  • Yes, I tried setting the file endcoding from the File menu, both on the .coffee and .js file but still doesn't help. Commented Jul 4, 2015 at 15:58

2 Answers 2

2

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:

screen 1

Or through the 'File Encodings' settings window itself:

screen 2


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.

Sign up to request clarification or add additional context in comments.

Comments

0

If you're using the standard Windows command prompt, you need to make sure that both the UTF8 code page is being used (chcp 65001) and that you are using the Lucida Console font instead of the Raster Fonts.

After making these changes, the text is shown just fine for me, both in the REPL and when executed from a file.

1 Comment

I tried this but it does not solve the problem. I don't think that the problem is with the settings in the console, bacause in this project I have folders that are in Bulgarian and they look fine in the console. It is only when I execute the js file. It must be from the settings of Webstorm. I will edit my question and attach an image from the settings of Webstorm.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.