JavaScript from absolute zero · Chapter 1 of 14 · Languages · new chapter every Tuesday morning
By the end of this chapter: Run JavaScript on your own machine within the hour, with nothing installed beforehand.
The problem
Emma is a marketing assistant who has just been asked to test a tiny piece of JavaScript that a colleague promised would “show the current date on any computer”. She opens the shared folder, double‑clicks the file show-date.js, and a blank window flashes before disappearing. The file contains the single line
console.log(new Date());
Emma sees no output, and the file’s owner replies that the script must be “run from a terminal”. Emma has never opened a terminal, never typed a command, and now she has wasted an hour trying to guess what “run from a terminal” means. The delay means the marketing campaign is postponed, and the team loses confidence in her ability to handle simple technical requests.
The goal of this chapter is to get anyone—no matter how unfamiliar they are with computers—to run that exact line on their own machine within an hour, with nothing pre‑installed.
Before you start
- Operating system – Windows 10/11, macOS 13 (Ventura) or a recent Linux distribution (Ubuntu 22.04 or similar).
- Node.js – version 20.10.0 (the current LTS at the time of writing).
- A text editor – any program that can create plain‑text files (e.g., Notepad on Windows, TextEdit in plain‑text mode on macOS, or gedit on Linux).
Verify the setup
- Open a terminal (see the next section for how to open one on each OS).
- Run
node -v
Expected output (exact wording may differ by patch level):
v20.10.0
If you see that version number, the runtime is correctly installed and reachable from the command line. If the command is not found, return to the installation steps in the next section.
What does it mean to “run a program”?
A program is a set of instructions that a computer can execute. The instructions are stored in a file—a collection of characters saved on disk. To run a program means to ask the computer to read that file, interpret each instruction, and perform the actions described.
In the context of JavaScript, the instructions are written in the JavaScript language. Normally a web browser interprets JavaScript when you load a web page, but browsers are not the only places JavaScript can run. A runtime is a piece of software that knows how to read JavaScript files and execute them. When you “run a program from a terminal”, you are invoking a runtime directly from the command line (the text‑based interface where you type commands).
The output of a program is whatever the program tells the runtime to display. In our example, console.log() tells the runtime to write a line of text to the standard output stream, which the terminal shows as text.
Where does JavaScript run outside the browser?
The most common runtime for non‑browser JavaScript is Node.js (often shortened to Node). Node bundles the JavaScript engine used by Chrome (V8) together with a set of libraries that let JavaScript interact with the operating system—reading files, making network requests, printing to the console, and more.
Why use Node for a first‑time run?
- No browser needed – you do not have to open a web page or understand HTML.
- Consistent behaviour – the same version of V8 runs on every platform, so the output you see on Windows will be the same on macOS or Linux.
-
Simple command – a single line
node file.jsexecutes the file.
The trade‑off is that Node adds a small download (≈ 30 MB) and you must manage its version, but for a learning exercise this cost is negligible.
How to get a JavaScript runtime on your computer
1. Download the installer
-
Windows – go to https://nodejs.org/en/download/ and click Windows Installer for the LTS version (the file will be named something like
node-v20.10.0-x64.msi). -
macOS – on the same page, click macOS Installer (e.g.,
node-v20.10.0.pkg). - Linux – the easiest route is the package manager. On Ubuntu, open a terminal and run
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
(The curl command fetches a script that adds the official Node repository; sudo runs the following command with administrator rights.)
2. Run the installer
- Follow the on‑screen prompts. Accept the licence, keep the default installation path, and allow the installer to add Node to your PATH (environment variable that tells the terminal where to find executables).
3. Verify the installation
Open a new terminal window (closing the old one ensures the updated PATH is read) and type:
node -v
You should see v20.10.0 (or a later LTS version). If you see an error like node: command not found, the installer failed to modify PATH; see the “When this breaks” section.
Build it
Below are the concrete actions that turn Emma’s vague request into a working result.
- Create a JavaScript file
- Open your text editor.
-
Paste the following line:
console.log(new Date()); Save the file as
show-date.json your Desktop (or any folder you can easily navigate to).Why: The file name ends with
.js, the conventional extension that signals “this is a JavaScript source file”.
- Open a terminal in the file’s folder
-
Windows – open File Explorer, navigate to the folder, type
cmdin the address bar, and press Enter. -
macOS – open Finder, go to the folder, right‑click and choose New Terminal at Folder (or open Terminal and run
cd ~/Desktopif you saved it on the Desktop). -
Linux – open your file manager, right‑click the folder and select Open in Terminal, or use
cdto change directory.
Confirm: The prompt should show the path, e.g., C:\Users\Emma\Desktop> or /home/emma/Desktop$.
- Run the file with Node
node show-date.js
Expected output (example):
2026-10-20T14:32:11.456Z
Why: node tells the runtime to execute the file that follows. The console.log statement prints the current date and time in ISO format.
- Confirm the result
- If you see a line that looks like a date and time, the program ran successfully.
- If you see an error, note the exact wording and move to the “When this breaks” section.
You have now executed a JavaScript program on your own machine without any prior setup.
When this breaks
1. “node is not recognized as an internal or external command”
- Symptom – the terminal prints:
'node' is not recognized as an internal or external command,
operable program or batch file.
Cause – the installer did not add the Node binary directory to the system PATH.
-
Fix –
-
Windows – open Start → Environment Variables, edit the
Pathvariable, and add the folderC:\Program Files\nodejs\. Restart the terminal. -
macOS/Linux – add the line
export PATH="/usr/local/bin:$PATH"to~/.bash_profile(or~/.zshrcon newer macOS) and runsource ~/.bash_profile.
-
Windows – open Start → Environment Variables, edit the
Verify with node -v again.
2. Syntax error in the file
-
Symptom – after running
node show-date.jsyou see:
SyntaxError: Unexpected token '}'
Cause – the JavaScript parser found characters that do not form a valid statement, often due to a missing or extra punctuation mark.
Fix – open
show-date.js, ensure the file contains exactly the line shown earlier, save, and re‑run.
3. Permission denied (Linux/macOS)
- Symptom – the terminal prints:
bash: node: Permission denied
Cause – the Node binary is not executable for your user.
Fix – run
chmod +x $(which node)to add execute permission, then retry.
4. Wrong directory
Symptom – Node reports
Error: Cannot find module '/path/to/show-date.js'.Cause – you are not in the folder that contains the file.
Fix – use
ls(Linux/macOS) ordir(Windows) to list files; ensureshow-date.jsappears. Change directory withcd path/to/folder.
These are the most common obstacles for a first‑time run. Once resolved, the workflow becomes reliable.
What it costs
- Installation size – Node adds roughly 30 MB to disk usage. On a machine with limited SSD space, this is a measurable cost.
-
Version lock‑in – Scripts written for a specific Node version may break if the runtime is upgraded without testing. The solution is to use a version manager (e.g.,
nvm) once you progress beyond this chapter. - Security surface – Installing any executable from the internet introduces a potential attack vector. Node’s installer is signed by the Node.js Foundation; verify the signature if you work in a high‑security environment.
- Learning curve – Understanding PATH, terminals, and file extensions adds cognitive load. However, these concepts are universal across programming languages, so the cost pays off later.
In short, the cost is modest and outweighed by the immediate benefit: being able to execute JavaScript directly.
In the interview
- Typical junior‑level question – “How would you run a single line of JavaScript on a computer that has no browser installed?”
Weak answer: “I would open Chrome and type it in the console.”
Why weak: It assumes a browser is present and does not address the “no browser” constraint.
Strong answer: “I would install Node.js, create a file with a .js extension, and run node filename.js from a terminal. I would verify the installation with node -v and confirm the output matches the expected result. If node is not on the PATH, I would adjust the environment variable accordingly.”
This answer mentions the trade‑off (installing a runtime), the constraint (no browser), the failure mode (PATH), and a concrete metric (checking the version).
- Senior‑level extension – “What are the implications of using Node for a quick script versus a browser‑based console, and how would you manage version drift in a team?”
A senior candidate should discuss the overhead of managing Node versions, the reproducibility benefits of using a version manager, and the security considerations of running arbitrary scripts.
- Follow‑up to separate experience from theory – “Can you describe a time when you ran a script on a CI server and encountered a ‘node not found’ error? How did you resolve it?”
Candidates who have actually performed the steps will reference PATH configuration or the use of a node Docker image, demonstrating hands‑on experience.
Your tasks
- Create and run a “Hello, world!” script
Write a file hello.js that prints the text Hello, world! using console.log. Run it with Node and verify the exact output appears.
- Display an environment variable
Add a line to hello.js that prints the value of the PATH environment variable (process.env.PATH). Run the script and note the long string that appears.
- Introduce a deliberate syntax error
Edit hello.js to remove the closing parenthesis from the console.log call. Run the script, capture the error message, and then fix the file so it runs again.
- Run the script from a different directory
Move hello.js to a sub‑folder called scripts. From the parent folder, execute node scripts/hello.js. Confirm the script still runs without changing the working directory.
-
Automate the run with an npm script (requires the next chapter’s knowledge of npm, but you can still create a
package.jsonmanually)
Create a package.json containing a "start" script that runs node hello.js. Execute the script with npm start and verify the same output.
Each task is considered complete when the terminal shows the expected output and no error messages remain.
Your tasks this week
Do the exercises above before the next chapter. Reading a tutorial and doing
one are different activities and only one of them changes what you can build.
Stuck on any of them? Say so — describe what you tried and what happened:
tell me where you got stuck. I read every one, and the questions
that come back more than twice get answered in the next chapter.
JavaScript from absolute zero
Chapter 1 of 14. New chapter every Tuesday morning.
Next: Values, variables and types.
· The full syllabus and every chapter so far
· Subscribers also get the condensed notes for this chapter, the running
recap of everything the series has covered, and the extended guidance:
subscribe
Written by Amit Chakraborty — founding engineer and senior architect: React Native, AI and RAG systems, production architecture. Portfolio · LinkedIn · GitHub.
Need this built, reviewed or taught to your team? Get in touch or email amit@devamit.co.in. Available for senior and founding engineering roles, consulting and training, remote worldwide.
Top comments (0)