Q1When you have only saved the source code, which part is that file kept in?
What a Program Is — How It Relates to CPU, Memory, and Storage
This article is part of the IT Foundations course, which builds up from scratch the practical IT knowledge you need at a minimum for programming and vibe coding.
A program is a sequence of instructions, and when you run it, it is loaded into memory and the CPU carries them out one at a time. Diagrams show why saving alone does not run it, starting from how the three parts divide the work.
This article covers what happens inside the computer when a program runs.
Saving a file and running it are separate events inside the computer.
The difference comes down to what each of the three parts — CPU, memory, and storage — is responsible for.
- A program is a sequence of instructions, and running it moves through them one line at a time from the top
- How CPU, memory, and storage divide the work, and what disappears when the power goes off
- Why saving alone does not run it — the writing goes no further than storage
- What "run this" in a set of steps hands to the runtime
A program is a series of instructions, and running it moves through them from the top
A program is the instructions you want the computer to carry out, arranged in the order they are carried out.
The human-readable text of it is the source code, and carrying it out one instruction at a time from the top is running it.
The three lines down the left of the diagram are the contents of app.js, and the CPU only ever receives one line at a time.
A line that only remembers a value puts nothing on screen.
When the third line finishes, the run itself ends, and the values remembered along the way do not remain.
If an instruction partway through cannot be carried out, the run ends there.
In the next three lines, the name gokei in the middle is not written anywhere.
console.log("Printing the total");
gokei();
console.log("Finished");
"It stopped with an error" means the run ended before reaching the last line.
The first line still appears on screen, the middle line produces the error text, and the last line ends without being read.
A program is a sequence of instructions carried out from the top
A program is what you want done, written out in order.
Running it means carrying out that sequence one item at a time from the top, and if a line partway through cannot be carried out, the lines after it end without being read.
What CPU, memory, and storage are each responsible for
The "computer" in the previous diagram is made of three parts with different roles.
The CPU (Central Processing Unit) carries out instructions one at a time, memory holds the contents only while something is running, and storage keeps things even when the power goes off.
One file in storage becomes a sequence of instructions inside memory, and the CPU receives only one of them at a time.
Values from partway through a calculation also sit in memory, and the file in storage is not rewritten while it runs.
The three parts are divided up inside one computer as follows.
- The app.js file you saved
- Remains as it is even when the power goes off
- The contents of app.js that were loaded
- Values remembered along the way, such as 150 and 200
- All of it disappears when the power goes off
- Receives only the one instruction it is carrying out now
- It no longer holds the instructions that are finished
Only the contents move along; the app.js in storage itself stays where it is.
What goes into memory is only what is running right now and the values from partway through it.
This distinction also shows up in how you read the warnings a computer produces.
"Out of memory" is about memory, so deleting files usually does not increase it.
"Low disk space" is about storage, and deleting files does free that up.
Where things are kept and where they run are different
Storage is where files are kept, memory is where what is running right now is held, and the CPU is what carries out those instructions one at a time.
What you wrote to storage remains when the power goes off, and what was in memory disappears.
Why saving a file alone does not make it run
Saving means writing the characters of the source code to storage.
They are written into the folder of my-app, the booking app you are building.
- app.js — the source code you saved
- Saving again changes the contents of this file
- Photo and document files
- Files that are not running sit there as they are too
The CPU never goes and reads a file placed here on its own.
When you have only saved, not a single instruction has been carried out yet.
| Step | Storage | Memory | Screen |
|---|---|---|---|
| Save only | app.js is written | Nothing goes in | Nothing appears |
| Save and run | app.js is unchanged | Loaded and starts running | 350 appears |
The save-only row stops at storage, and since nothing goes into memory, the CPU receives no instructions at all.
Nothing happens on screen because you have not told it to run.
When you run it again, the old contents of memory are discarded and the new file is loaded.
What you fixed runs at the moment that reload happens.
This is why a set of steps tells you to run it again.
Saving is not the same as taking effect
Saving goes no further than writing the characters to storage.
A running program keeps going with the contents as they were when it was loaded, so even if you fix the file, the result on screen does not change until you run it again.
"Run this" means handing a file to the runtime
The runtime — the software that reads source code and has the CPU carry out its instructions — is what loads the file into memory and delivers the instructions to the CPU.
"Run this" in a set of steps means handing the file to this runtime.
The only thing you type yourself is the one line on the far left.
That one line shows up in a set of steps in this form.
# Run JavaScript (Node.js) source code
node app.js
# Run Python source code
python app.py
This one line is a command — an instruction in text that tells software what to do.
The front is the name of the runtime and what follows is the file name of the source code, separated by a space.
- node — reads JavaScript source code
- python — reads Python source code
- app.js — the file name of the source code you saved
- The runtime loads this from storage
- A short name decided in advance is sometimes written instead of the file name
The front tells you which runtime is needed, and what follows tells you which file gets loaded.
The screen where you type this line is covered in this course's article "What a Development Environment Is."
Even when the language changes, the reading stays the same: the front is the software that receives it, and what follows is what you hand to it.
There is one more place where the wording of the steps differs.
How things end after you tell it to run splits into two.
The lower branch is the kind of program a set of steps tells you to leave running.
Some runtimes reload the file automatically every time you save.
Even then, the screen changes only after the new file has been loaded.
Telling it to run means handing over a file
"Run this" means hand the file to the software called the runtime.
You hand it over with one line such as node app.js, and some programs run to the last line and end while others do not end until you stop them.
Knowledge Check
Answer each question one by one.
Q2What does a computer do when it "runs a program"?
Q3In the command node app.js, what does the node at the front refer to?