Chrisstar
Chrisstar

Reputation: 656

NodeJS output doesn't display Strings correctly in Windows "cmd"

My NodeJS console.log() function no longer displays Strings correctly in Window's cmd. They render as black text with a black background. I don't remember changing anything that could have lead to this.

I'm pretty sure it's the colors, though not the ones of the terminal itself (I've tried changing those), since when I copy the text, it has the correct output. I've included a screenshot of how it looks.

Screenshot:

Screenshot

Text output:

{ key1: 'value',
  key2: 51,
  key3: 2019-05-31T08:05:51.492Z,
  key4: [ '12', '23', '24' ] }

Has anyone else had the same problem? What could have caused this (wasn't always like this).

EDIT: From what I gathered, the Object.toString method is causing the objects to display incorrectly. Node tells me it is native code though. What could be causing this issue?

Upvotes: 0

Views: 94

Answers (2)

Chrisstar
Chrisstar

Reputation: 656

So I figure it out. Something (I don't know what, I doubt I did that accidentally) changed a few of the cmd colors in the registry, causing them to be black. I don't know what could have caused this, but it works now at least. If you ever stumble upon the same problem, look up the color values at HKEY_CURRENT_USER\Console and look if some of the Color table values may be se to zero. I was able to find some values of another user, and while they weren't exactly the ones it was originally set to, they fixed it.

Upvotes: 0

Slawomir Chodnicki
Slawomir Chodnicki

Reputation: 1545

Looks like maybe somebody monkey-patched console.log and used something like https://www.npmjs.com/package/cli-highlight to color the output before it is written.

I'd ask around in your team and search for commits mentioning console in your source code repository.

If you can, check the behavior on a different environment, to learn whether it's something specific to your machine, like your terminal configuration.

Upvotes: 1

Related Questions