What you'll learn
Node.js lets you run JavaScript outside the browser and gives your programs access to files, processes, networking, and the operating system. You will install the LTS release, explore the REPL, run a script, and pass real input from the terminal.
By the end of this lesson, you'll be able to:
- Explain the difference between JavaScript, the V8 engine, and Node.js
- Install and verify a supported Node.js LTS release
- Experiment in the REPL and execute a .js file
- Read command-line arguments and return meaningful exit codes
Core mental model
Node.js becomes easier when you separate the JavaScript language from the runtime and the operating-system capabilities it exposes. Use this table as a decision guide.
| Concept | What it means | Decision rule |
|---|---|---|
| JavaScript | The language: values, functions, objects, promises, and syntax | Language features work across runtimes unless they depend on a host API |
| Node.js runtime | V8 plus APIs for files, processes, networking, timers, and more | Choose Node.js for server-side programs, automation, tools, and APIs |
| LTS release | A release line intended for longer production support | Use the current LTS line for learning and most production projects |
| REPL vs script | The REPL evaluates experiments; a script saves repeatable behavior | Explore in the REPL, then move useful code into versioned files |
Professional workflow
Build and verify Node.js programs from the terminal in small, observable steps.
- Install the current LTS release from the official Node.js download page or a trusted version manager.
- Open a new terminal and verify both node and npm are available.
- Use the REPL for a tiny expression, then exit without leaving a process running.
- Create a project folder and save the first program as hello-node.js.
- Run the file from its own folder, change an input, and run it again.
- Trigger one expected error and practice reading the file, line, and message in its stack trace.
Keep the feedback loop short
Guided code lab
Verify the installation and enter the REPL
The version commands prove that your terminal can find Node.js and npm. Running node without a filename opens the Read–Eval–Print Loop; .exit closes it.
node --version
npm --version
node
> 6 * 7
> process.platform
> .exitRun your first Node.js file
A script is repeatable and shareable. Node supplies the process object; JavaScript supplies strings, objects, and console.log.
const learner = {
name: "Maya",
goal: "build reliable backends",
};
console.log("Hello, " + learner.name + "!");
console.log("Goal: " + learner.goal);
console.log("Running on " + process.platform + " with Node " + process.version);Accept input from the command line
process.argv is an array. The first two entries identify Node and the script, so user arguments begin at index 2. Validate them before doing work.
const [, , rawName] = process.argv;
const name = rawName?.trim();
if (!name) {
console.error("Usage: node greet.js <name>");
process.exitCode = 1;
} else {
console.log("Welcome to Node.js, " + name + "!");
}Production practice
Pin expectations
Document the supported Node.js range in the project README now; later you will also express it in package.json.
Use exit codes
Write human-readable errors to stderr and set a non-zero exit code when a command cannot complete.
Keep secrets out
Never place passwords, tokens, or private keys directly in source files or command examples that will be committed.
Common failure mode
Independent workshop
Build a command-line developer profile that accepts a name and favorite technology, then prints a clean three-line introduction.
Your finished workshop must include:
- A profile.js script using command-line arguments
- Friendly usage instructions when either argument is missing
- A success exit code and a non-zero validation exit code
- A README containing the exact commands for both paths
Definition of done
Recap & quick check
Key takeaways
- Node.js is a JavaScript runtime, not a separate programming language.
- The current LTS release is the sensible default for most learners and production work.
- The REPL is for fast experiments; files make programs repeatable.
- process.argv carries terminal input, while process.exitCode communicates success or failure.
Quick check
1. What does Node.js add around the JavaScript engine?
2. Which command opens the Node.js REPL?
3. Where do user-supplied arguments normally begin in process.argv?
4. What should a failed CLI command communicate?
Next: JavaScript Essentials for Node.js