I've been trying to look for a solution but I can't seem to find one. I am a beginner to nodejs and basically I have created a new nodejs file called "app.js" inside of a directory called "HelloNode". When I use "node app.js" inside of powershell, the terminal tells me this:
This is the image of my screen
Code in VS Code:
var msg = "hello world";
console.log(msg);
Output in terminal:
PS C:\Users\yanab\HelloNode> node app.js
C:\Users\yanab\HelloNode\app.js:1
��v
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:791:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
Solutions I have tried:
Notes:
Solution: Well I basically just made the file inside of vscode by right click -> new file and it worked. What I did before was use powershell and the command echo to make a new file. Don't understand what happened but making the file inside of vscode seems to be the solution.
I had the same situation. It turns out the file was UCS-2 encoded. After converting it to UTF-8 using notepad ++, it started working fine.
In my case, the reason for the UCS-2 encoding was the way I was filling out the file: echo 'console.log("Hollow world");' > test.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With