utf8 console.log output using node.js - node.js

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');

Related

How to navigate from running python script in ubuntu terminal?

I am currently running a python3 script in Ubuntu server 18.04. When i type new commands into the command line it just prints the commands. My terminal window looks like this:
mitch#server:`$ cd /home/mitch/folder
mitch#server:`/folder$ python3 main.py
file running ...
text i input just shows like this
I need to keep the script running and run other commands, how do i navigate back to:
mitch#server:`
I'm new to servers/Ubuntu/commands so this may seem trivial! Thank you
So you can't "navigate" back to that, since you're technically already there, you're just running a script in your shell which is occupying your shell - think of it like you opened a program in full screen.
But you have a few options:
The most basic is to run the script in the 'background' this is a simple as adding a & to the end of your command (note that it will still send any message from the script into your terminal - if your script is programmed to send messages that is).
Another option is to use a terminal multiplex like which lets you have multiple terminals open, as well as split screen terminals and many other features. One of the more popular multiplexers is called tmux, just keep in mind that it does have a bit of a learning curve to it, but is extremely useful once you learn it.

I can't get pythons output viewer to run

I just downloaded python on a new pc and now whenever I try to create a script the output viewer just closes down immediately when I launch it as a python file.
My original script was
import secrets
secrets.token_hex(32)
but it just closes down immediately. I thought that it was something with my code so I tried to just make the simple "hello world" script.
(print) "I hope this work"
and I had the same result as the first script, the output window opened up then immediately closed down.
I can get it to work using the python shell but I prefer doing all my coding using notepad++ and it would a real pain in the behind if I can't get that to work.
This is expected behavior if you run your scripts as you described, by opening them in Explorer. Your script completes execution in a terminal window, then closes immediately.
If you absolutely insist on running them on double click and still want to see your console, I suggest you create a .bat file at your python path with contents like this:
python -i %1
and them bind your double-click handler to use that file on .py extension. That way, Python will execute your file and go into CLI mode, preserving your terminal window and allowing you to type further commands.
My other guess would be that you want a console plugin to work right within Notepad++, in that case use nppexec: https://sourceforge.net/projects/npp-plugins/files/NppExec/

Access output in Ubuntu 14.04 terminal that has 'disappeared' off the terminal window

I just ran a script on a server that generates a lot of output on the command window.
However, now, after running it for roughly 4 hours I want to check all the output, but the beginning of the output has already disappeared from the terminal window. When I scroll up, it is not there anymore.
Is there any way to access this? It needs to be via commands in the terminal because I'm running it on a server.
Thanks.
Best way is to redirect the output to a file & open the file to check for all the output.
You can also redirect the script by running it in background & saving the output to a file. Do let me know what type of command you are running for which I can give you the exact command. :)
if it's a real terminal and not a virtual terminal
you need to recompile your kernel and increase the buffer size of your terminal.
in the .config file of your kernel the parameter you need to increase is
CONFIG_VGACON_SOFT_SCROLLBACK_SIZE
Actually, redirecting I/O interferes with many programs (for instance, changing the output from a tty to a plain file). Use the script program to capture all output from programs run in a shell, with minimal interference.

How can I print a utf8 string in the console using nodejs

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.

Node command line interface change

I'm making a command interface for a node server, but I have reached a point that I want it to look better.
I want to have the console so you enter a command at the bottom of the terminal screen, you hit enter, and it adds the reply to the actual command line.
If you have ever run a minecraft bukkit server from the command line, you should know what I'm talking about.
Here's a picture of what I'm talking about if you still don't understand. Imagine this was in terminal, and ignore the scroll bars: http://cl.ly/1K0h1V0r0H3f3U3t3L22
Is there anyway to set the console to look like this without having to make your own program for it or having the screen reprint all the other info to fake that look?
I have not done this, but I believe something similar is possible with very little effort by using Node.js REPL. You can override the eval parameter to provide your own command processing.
It would not have the exact look you are wanting, but it will be an interactive prompt that you can utilize (more similar to a Windows command shell or a Linux shell).
If you want the exact look from your screenshot, I don't believe that there is any Node.js module that will help you. There are some that allow you to use colors in the console, and some basic highlighting (e.g. bold), but nothing that gives you complete control over the console screen.

Resources