Calling NodeJs script from Powershell - Encoding problem

Viewed 123

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?

1 Answers

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

[console]::OutputEncoding = New-Object System.Text.UTF8Encoding
Related