0
0
Node.jsframework~10 mins

Running scripts with node command in Node.js - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Running scripts with node command
Write JavaScript file: script.js
Open terminal/command prompt
Type: node script.js
Node reads script.js
Node executes code line by line
Output shown in terminal
Script ends
This flow shows how you write a JavaScript file, run it with the node command, and see the output in the terminal.
Execution Sample
Node.js
console.log('Hello from Node!');
This code prints a message to the terminal when run with node.
Execution Table
StepActionEvaluationResult
1Node reads script.js fileReads code: console.log('Hello from Node!');Code loaded
2Execute console.log statementPrints 'Hello from Node!'Message shown in terminal
3End of script reachedNo more code to runScript stops
💡 Script ends after all lines are executed
Variable Tracker
VariableStartAfter 1Final
No variablesN/AN/AN/A
Key Moments - 3 Insights
Why do I need to type 'node script.js' in the terminal?
Typing 'node script.js' tells the computer to use Node.js to run the JavaScript file named script.js, as shown in execution_table step 1.
What happens if I run 'node' without a file name?
Node will open an interactive prompt instead of running a file, so no script runs until you type code manually.
Why does the output appear in the terminal?
console.log sends output to the terminal where you ran the node command, as seen in execution_table step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what does Node do at step 2?
AEnds the script
BReads the script file
CPrints the message to the terminal
DWaits for user input
💡 Hint
Check the 'Action' and 'Result' columns at step 2 in the execution_table
At which step does the script stop running according to the execution table?
AStep 3
BStep 1
CStep 2
DAfter step 3
💡 Hint
Look at the 'Step' and 'Result' columns to find when the script ends
If you change the file name to 'app.js', what command should you run to execute it?
Anode script.js
Bnode app.js
Cnode run app.js
Drun node app.js
💡 Hint
The command uses 'node' followed by the exact file name, as shown in concept_flow
Concept Snapshot
Run JavaScript files with Node.js using the command:
node filename.js
Node reads and executes the file line by line.
Output from console.log appears in the terminal.
Script ends when all code runs.
Use terminal or command prompt to run scripts.
Full Transcript
To run JavaScript code with Node.js, you first write your code in a file, for example script.js. Then, you open your terminal or command prompt and type 'node script.js'. Node reads your file and executes the code inside it line by line. If your code uses console.log, the messages will appear in the terminal. When Node finishes running all the lines, the script stops. This process lets you run JavaScript outside of a browser easily.