Could someone help me why my code doesn’t run on terminal? First I chose the folder where I saved the file I want to run, then I write node with file name and nothing happens. I did exactly like in tutorial on codeacademy, but I don’t understand why it’s not running.
Did you save the file, “practice.js” before typing the command
I did save it, and it is in folder, and when I request list of recent folder on terminal, it does show on the list my file, but when I try to run, nothing happens.
Have you saved the file since adding the
Yes, I saved after I add console.log
No error messages?
No error, nothing. Tired louds of times and always the same like in screenshot, no outcome…
From the directory where the “practice.js” file is located, can run the
dir command, and post a screenshot?
Ok. Now in that same terminal window execute
type practice.js, and post a screenshot.
It runs now!
So basically, when I typed ‘type practice.js’ it printed me, what I wrote in this file before. I deleted previous code and wrote only that one ‘let a = 5’ and saved it again. Every time I open and close the file, it opens the new one I wrote, but on terminal prints old one. Does it mean that if I make some changes in saved file and saving that file with new changes on the top, terminal would only read what was before I made changes? And if I want terminal to read my file with new changes do I need always to save as a new file? If that make sense to you…
Not sure I follow you completely, but it sounds like you have multiple instances of “practice.js” in different locations. If you are using VS Code to edit the file, make sure you are in the same location as the file shown in your screenshot. When you execute
node practice.js it will run the program with whatever was saved last in that exact file.
That’s what I thought, but when I saved after changing the file, terminal still was printing what was before changes. So after I tired to save as a new file, so then all was good and changes was saved, but if every time when I make some changes I need to save in new file, it’s weird…
Sounds like you are editing a file named practice.js in one folder, but when you click
Save As you are overwriting the file at
"C:\Users\Beatrice\Desktop\Coding\practice.js". We can check this theory if you’ll open a terminal in VS Code, and post a screenshot. Will look similar to this:
As well what I noticed, at first I saved everything on local disc D, but terminal checks files on disc C. I didn’t know how to make path to disc C on terminal, so I simply copy and paste my folder with my codding projects on desktop, so would be easier to make paths on terminal. But VS still was thinking that it saves files on disk D, so then I was making changes and pressing simply “save” it made new folder on disk D and kept saving there new files. So I had codding folders: one I copied to disk C and one VS still kept saving on disk D, so I just need to changes on VS my main place for saving files. I hope you understand how I explain, English is my second language, so sometimes I think my wording might be messy…
That makes sense, and explains the issue. Glad you figured it out. Happy coding!