1

I have a JavaScript file "test.js" and want to call this file from PowerShell.

test.js file:

async function main() {
  console.log("€");
}

main();

When I call the script from cmd I get the correct encoded result like "€"

C:\> node test.js -> €

When I call the script from PowerShell I get a wrong encoded result like "€"

PS C:\> node test.js -> €

When I call the script from PowerShell via cmd I get also a wrong encoded result like "€"

PS C:\> cmd /c node test.js -> €

What can I do the get the correct encoded result "€" in PowerShell?

Mannol
  • 39
  • 6

1 Answers1

1

change the encoding of your powershell host to UTF 8, nodejs is using this encoding by default.

[console]::OutputEncoding = New-Object System.Text.UTF8Encoding
mklement0
  • 382,024
  • 64
  • 607
  • 775
Clemens Sutor
  • 136
  • 1
  • 4