ProgramGuru

Installing Node.js

Learn Installing Node.js

Node.js provides a practical local JavaScript runtime and npm, which manages development tools including TypeScript.

In this lesson, you will study the rule, run a complete TypeScript example, explain its output, and test a small change.

What you’ll learn

  • Explain the main rule behind installing node.js.
  • Predict the result of the complete runnable TypeScript example.
  • Recognize one common mistake and correct it.

Understand the concept

Download an appropriate supported installer from nodejs.org, or use a version manager. Open a new terminal and verify node --version and npm --version. Node runs JavaScript emitted from TypeScript. Native handling of erasable .ts syntax is version-dependent and does not replace TypeScript type checking.

In a terminal run node --version and npm --version. Use the official Node.js download page.

Run a complete TypeScript example

Save this code as main.ts or paste it into the TypeScript Playground. The example uses fixed values so it runs without prompting for input.

TypeScript code

const runtimeName: string = "Node.js";
 console.log(`Ready to run JavaScript with ${runtimeName}`);

Verified output

Ready to run JavaScript with Node.js

How to run locally: npx tsc --strict --target es2022 --module commonjs main.ts, then node main.js. When using a project configuration, run the matching project build instead.

Trace the execution

The snippet uses no Node-specific APIs, so it will also run in a browser console after compilation. The purpose of installation is to obtain a predictable local command-line workflow.

Predict the output before you run the sample. Compare each line with the source expression that produced it, and distinguish the type checker’s work from what happens in JavaScript at runtime.

Common mistakes and how to avoid them

Do not assume your Node version accepts node file.ts. The universal beginner path here is check with tsc, emit .js, and run node file.js.

Debugging habit: when a change is rejected, read the exact compiler diagnostic and inspect the operand types. When it compiles but behaves unexpectedly, follow the values through the JavaScript expressions.

Practice it yourself

Install Node.js, run node --version and npm --version, then save the example as main.ts and follow the compilation workflow in the next lessons.

Challenge: write down your prediction first, run the changed source, and explain any difference. Return to the verified version before continuing.

Check your understanding

Which command verifies Node.js is available?
Choose one answer. You can try again.

Answer and explanation

node --version

node --version reports the installed Node.js version. npm has its own --version check.

Review the key idea

Installing Node.js: Download an appropriate supported installer from nodejs.

node --version reports the installed Node.js version. npm has its own --version check.

Before continuing, be able to explain what is checked before execution and what actually changes at runtime in the example above.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Installing TypeScript →