I am starting to read a beginners guide on node js. But I can't find how to create a file and then save it. As I see to execute it I do it with the command:
node nombredearchivo.js
But that's just to open, I read elsewhere that after writing the code, I would write that same command and my code would be saved. But it's not working...
You can create the file with any text editor, even with the
Notepad
windows one, then through the console, you would only have to go to the location of the file and do the command that you have put in your question, with that it wouldnode
already execute the file.If you installed node correctly, from the terminal and any directory, you could do
node --version
, if it shows you the version, it isnode
correctly installed and you can execute the commandnode
from any directory.Imagine then that you create a file
/home/archivo.js
from the terminal you do acd /home
and from there you would only have to donode archivo.js
this way and you would execute the file. Another question is that the file is being executed and since you don't paint anything on the screen you think that it is not being executed, try putting aconsole.log('Hello')
in yourarchivo.js
and see if it paints something on the console when you execute it.In linux it is the same as in the other operating systems, you simply have to have node installed, edit the file, save it and execute it: