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'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.
Related
It's maybe stupid question, but what happens behind the scenes when i double click the word app, or .exe app?
For 'Non-Developer' it just opens the file in right environment after doubleclicking. But I would like to know, how is it done, how can the file manager know what to open? (.docx in word, .txt in texteditor,etc...)
+ I would like to know how can I do that in Node.js, is it the best way to use child_process and if statements for every suffixes?
There is a file association to tell Windows how to treat a certain file extension. You can type assoc in a Windows Command Prompt to see them. As an example:
C:\test>assoc .txt
.txt=txtfile
So Windows knows now, that the file with the extension .txt is a txtfile.
ftype defines, how that filetype is to be handled:
C:\test>ftype txtfile
txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1
So whenever you doubleclick on a file, Windows checks if it is associated with any filetype. Then it looks up, how to handle that filetype and executes that command (in the example above, it opens Notepad with the filename as a parameter).
Both assoc and ftype are able to change the settings (for example to open .txt files with another editor). But if you try that, do yourself a favor and note the original settings, so you are able to revert your changes when needed.
The changes can also be done directly in the registry (not recommended, when you are not experienced in handling the registry)
For Node.js, you can use child_process to shell out to the start command which does similar things as the File Explorer.
E.g. start some/path/to/file.docx will open that file in the default program associated with the format.
This is such a basic question I am surprised I could not easily find an answer to it:
I use Notepad++ to write my scripts in. Someone sent me some code for a shell script (.sh) that I could modify to suit my needs. I simply changed a small bit of text using Notepad++ (on Windows) and used FileZilla (SFTP) to upload it to my server (Debian Linux).
There were a few problems with this that it took my server admin an hour to find, namely:
FileZilla, for whatever reason, defaults to ASCII rather than binary! (changed it to binary and removed the .sh association with ASCII)
The permissions were wrong, chmod took care of this
Problem is it STILL did not work. To fix it my server admin simply copied the text right on the server (using vim or nano) into a new shell script file and saved that. Before he kept saying the problem was Windows (which he loves to hate on) but it seems it is the encoding that text-editors are using that is corrupting the files.
He said my text-editor encoding needs to be said to "None". However, that is not an option - only ANSI, UTF and UTS variants are options!
How can I create a shell script on Windows with no encoding whatsoever so that it doesn't get corrupted?
I need to be able to simply transfer the file to the server, I can't mess around with modifying it once on the server which is wholly impractical.
To fix it EndOfLine and encoding on Notepad++ :
On the bottom right of Notepad++ you can right click on the left of the encoding "UTF-8" and click on Convert UNIX(LF) format. Be sure to change encoding to UTF-8 if it is not the case.
In Filezilla :
Transfert mode : auto
I am using ckeditor. when i work in localhost (in my pc) its working fine in formating and image upload.but when i work with it at server it formating and image upload is not working.
for ex. - if i formate font with some style and color and size its shows all effect front side on local but when i use same style same font and same color its not shows any formating or image on its front side.
for save that text i used mysql_real_escape_string() function i also tried mysql_escape_string() but both are working in local only not on server. :S
for image upload its path gose wrong into database so its not showing front side.
for ex.
local path -
(http://localhos/exo/uploads/24ysjdh.jpg)
server path - (http://mysite.in/%22/uploads/image/11/2qiz714.jpg/%22) (in this url %22 is making problem)
i dont know why the editor is working in local and not working in server. :S i faced this unique problem first time.
If you're using PHP MagicQuotes could be causing this. It seems like there is something wrong in the /uploads/image/11/2qiz714.jpg. There are extra /" wrapped around it is changing to /%22
/%22/uploads/image/11/2qiz714.jpg/%22
It is probably in code that generates the path. Are MagicQuotes turned on or off? Can you paste piece of your code that creates this path? once you find it double check that all the " and escaped /" are proper.
I have utf8 information coming for a mysql database.
I want to use console.log to output it to the console.
but it shows "box" characters instead of the utf8 data.
Where am I loosing the data ? and what should I do to fix this ?
is the problem when reading the data from the DB ? (using felixge-node-mysql-v0.9.5-1)
or during output to the console? (using console.log)
ot maybe its the console itself (windows command window set to font "Lucida Console")
Thanks.
UPDATE:
I now believe its an issue with the fonts of the windows command window.
when I run the same node script using a powershell window
I do see different chars that don't look like what I expect.
whoever, when I Try to paste then into this browser window they suddenly change to the right font and chars.
Although I would still love a better solution what I have found for now is the following solution that works for me:
I will use Windows PowerShell ISE.
Inside it I ran the following command:
chcp 65001
running node.exe my.js from the lowest pane in WPSISE results in the exact printout I wanted in the middle pane.
Another point to mention is that if I try to open a cmd.exe window and run chcp 65001 in it and then execute my script I get
node.js:284 throw new Error('process.stdout cannot be closed');
Guys,
I am looking for a text editor or method to deal with the UTF8 encoded *.properties file created by the Netbeans (6.x and 7.0.x). Trust me I have tried Notepad++, PsPad, gVim, jedit, etc without luck. Or I have just missed somehing?
The items is in the form of followings:
update.text=\u4FEE\u6539
The reason for this is I am trying to use script to modify some property items during the build process.
At the moment only Netbeans itself can read and display the content correctly. Any ideas?
Thanks.
David
I use WinVi, which supports UTF-8, UTF-16, and hex/binary editing.