I know that
Node.js allows to write JavaScript code that runs directly in a computer process itself instead of in a browser
Reading this, I try to open my terminal and run:
console.log('hello')
but I get zsh: unknown file attribute.
The same happens with node console.log('hello')
.
If I instead create a file hello.js
and put the console inside it and then I run:
node src/hello.js
it works. Why? What am I missing?
Sorry for the (maybe) stupid question
CodePudding user response:
It's because the console.log('hello')
is being evaluated by your shell (zsh
) before running the command and it has no idea what console.log('hello')
is. You could use the -e
or --eval
arguments.
$ node -e "console.log('hello')"
CodePudding user response:
If your using linux, first type node
It will profile for you a REPL. which is essecially the excution terminal.
You can also do the same on windows