Install JavaScript: Set Up Node.js and VS Code (Windows, macOS, Linux)
You do not install “JavaScript” itself. You install a runtime that runs JavaScript (Node.js) and an editor to write it in (VS Code). In this lesson you will install Node.js 26 LTS and npm, verify them, configure VS Code with the right extensions and settings, and create and run your first JavaScript project. The same setup is used in every lesson of this course and by Playwright, Cypress and Jest.
📖 What You’ll Learn: what Node.js, npm and VS Code are, LTS versus Current releases, installing on Windows, macOS and Linux (installer, winget, Homebrew, nvm), verifying the install, configuring VS Code, creating a project with npm init, npm scripts, watch mode and fixing the most common setup errors.
🧩 What You Will Install and Why
| Tool | What it is | Why you need it |
|---|---|---|
| Node.js | A JavaScript runtime built on Chrome’s V8 engine | Runs .js files on your computer, outside the browser |
| npm | Node Package Manager, installed with Node.js | Installs libraries (Playwright, Jest, ESLint) and runs project scripts |
| VS Code | A free code editor from Microsoft | Autocomplete, debugging, a built-in terminal and extensions |
Definition: an LTS (Long-Term Support) release is a Node.js version that receives bug and security fixes for about 30 months. Current releases get the newest features first but are supported for a shorter time. Always pick LTS for learning and for test projects.
| Release line | Status (checked 23 November 2026) | Use it? |
|---|---|---|
| Node.js 26 “Lithium” | Active LTS | Yes, recommended for this course |
| Node.js 24 “Krypton” | Maintenance LTS (security fixes) | OK if already installed |
| Node.js 22 “Jod” | Maintenance LTS until April 2027 | OK, but plan to upgrade |
| Node.js 27 | Current (pre-release) | No, not for learning |
📌 Note: Every example in this course was run on Node.js v26.13.0 with npm 11.20.0. Node.js 22 or later runs all of them.
🪟 Install Node.js on Windows
Option 1: the official installer (easiest)
- Open nodejs.org and download the LTS Windows Installer (
.msi) for your system (x64 for most PCs, ARM64 for Snapdragon laptops). - Run the installer. Accept the licence and keep the default folder
C:\Program Files\nodejs\. - On the “Custom Setup” screen keep Add to PATH selected. This lets you type
nodein any terminal. - The “Tools for Native Modules” checkbox is optional. Leave it unticked unless you need to compile native packages.
- Finish the installer, then close and reopen every terminal and VS Code window so they see the new PATH.
Option 2: winget (one command)
Windows 10 and 11 include the winget package manager. Run this in PowerShell or Command Prompt:
⌨️ Terminal
winget install OpenJS.NodeJS.LTS
💡 Tip: If you need several Node.js versions (for example one project on 22 and another on 26), use a version manager such as fnm or nvm-windows instead of the installer.
🍎 Install Node.js on macOS
Option 1: the official installer
Download the LTS macOS Installer (.pkg) from nodejs.org, open it and follow the steps. It installs node and npm into /usr/local/bin.
Option 2: Homebrew
⌨️ Terminal
brew install node
⚠️ Watch out: brew install node installs the newest release line, which may be a Current (non-LTS) version. To stay on LTS with Homebrew, install the versioned formula, for example brew install node@26, or use nvm (below).
🐧 Install Node.js on Linux (and macOS) with nvm
nvm (Node Version Manager) installs Node.js inside your home folder, so you never need sudo, and lets you switch versions per project.
- Copy the install command from the nvm README (it is a one-line
curl ... | bashscript) and run it in your terminal. - Close and reopen the terminal so the
nvmcommand is loaded. - Install and select the latest LTS version:
⌨️ Terminal
nvm install --lts
nvm use --lts
nvm alias default lts/*
The last command makes the LTS version the default in every new terminal.
✅ Verify the Installation
Open a new terminal (PowerShell, Command Prompt, or Terminal on macOS/Linux) and check the versions:
⌨️ Terminal
node -v
npm -v
🖥️ Output
v26.13.0
11.20.0
Your patch numbers may be higher, which is fine. Now run one line of JavaScript straight from the terminal with node -p (“print”):
⌨️ Terminal
node -p "process.platform + ' ' + process.arch"
🖥️ Output (on Windows)
win32 x64
On a Mac with Apple silicon you would see darwin arm64, and on most Linux PCs linux x64.
📁 Create and Run Your First JavaScript Project
A Node.js project is just a folder with a package.json file. package.json stores the project name, its scripts and the packages it depends on.
⌨️ Terminal
mkdir js-course
cd js-course
npm init -y
🖥️ Output
Wrote to C:\Users\you\js-course\package.json:
{
"name": "js-course",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs"
}
-yaccepts all default answers, so npm does not ask questions."type": "commonjs"means.jsfiles in this folder use the CommonJS module system (require). You will learn about ES modules (import) in Module 11.
Create a file called app.js in the folder with this content, then run it:
📄 app.js
console.log("Hello from Node.js", process.version);
⌨️ Terminal
node app.js
🖥️ Output
Hello from Node.js v26.13.0
Add npm scripts
npm scripts are named commands stored in package.json. Add two scripts with npm pkg set (or edit the file by hand):
⌨️ Terminal
npm pkg set scripts.start="node app.js" scripts.dev="node --watch app.js"
📄 package.json (scripts part)
{
"name": "js-course",
"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",
"dev": "node --watch app.js"
},
"type": "commonjs"
}
⌨️ Terminal
npm start
🖥️ Output
> js-course@1.0.0 start
> node app.js
Hello from Node.js v26.13.0
npm run dev starts watch mode: Node.js reruns app.js every time you save it, which is ideal while practising. Press Ctrl+C to stop it.
⌨️ Terminal
npm run dev
🖥️ Output
Hello from Node.js v26.13.0
Completed running 'app.js'. Waiting for file changes before restarting...
🧑💻 Install and Configure VS Code
- Download VS Code from code.visualstudio.com and install it. On Windows, tick Add “Open with Code” action and Add to PATH.
- Open your project: File › Open Folder… and choose
js-course, or typecode .in a terminal inside the folder. - Open the built-in terminal with Ctrl+` (back-tick). It starts in your project folder, so
node app.jsworks straight away.
Recommended extensions
| Extension | ID | What it does |
|---|---|---|
| ESLint | dbaeumer.vscode-eslint | Underlines likely bugs (set up in Module 11) |
| Prettier – Code formatter | esbenp.prettier-vscode | Formats code automatically on save |
| Error Lens (optional) | usernamehw.errorlens | Shows errors inline, next to the code |
Install an extension from the Extensions view (Ctrl+Shift+X), or from the terminal:
⌨️ Terminal
code --install-extension esbenp.prettier-vscode
code --install-extension dbaeumer.vscode-eslint
Recommended settings
Open Command Palette (Ctrl+Shift+P) › Preferences: Open User Settings (JSON) and add:
📄 settings.json
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2,
"files.autoSave": "onFocusChange",
"javascript.updateImportsOnFileMove.enabled": "always"
}
formatOnSave+ Prettier: your code is tidied every time you save.tabSize: 2: two-space indentation is the JavaScript convention.autoSave: files save when you switch to the terminal, so you never run an old version.
💡 Tip: Turn on type checking in plain JavaScript files by adding // @ts-check as the first line. VS Code then underlines mistakes such as calling a method that does not exist, using the TypeScript engine it already includes.
🛠️ Fix Common Setup Errors
“node is not recognized” on Windows
🖥️ Output
'node' is not recognized as an internal or external command,
operable program or batch file.
Cause: the terminal was opened before Node.js was installed, or “Add to PATH” was unticked. Fix: close every terminal and VS Code window and open them again. If it still fails, rerun the installer and keep Add to PATH selected.
“command not found: node” on macOS or Linux
Fix: open a new terminal. With nvm, run nvm use --lts; if nvm itself is not found, the install script could not update your shell profile (~/.zshrc or ~/.bashrc). Follow the “Troubleshooting” section of the nvm README.
npm blocked in PowerShell
🖥️ Output
npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system.
Fix: allow scripts signed or created on your computer for your user only, then reopen PowerShell:
⌨️ Terminal
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
If your company manages this setting, use Command Prompt instead, where npm runs npm.cmd and is not affected.
“Cannot find module” when running a file
📄 app.js
console.log("this file exists");
⌨️ Terminal
node ap.js
🖥️ Output
node:internal/modules/cjs/loader:1607
throw err;
^
Error: Cannot find module 'C:\Users\you\js-course\ap.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:1603:15)
... (more Node.js internal lines)
at node:internal/main/run_main_module:33:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v26.13.0
Cause: a typo in the file name, or the terminal is in a different folder. Fix: check the name and run pwd (macOS/Linux/PowerShell) or cd (Command Prompt) to see the current folder.
📝 Practice Questions with Answers
Try each question on your own first, then open the answer to check your work. Run the code with node practice.js.
Q1. Which command prints only the installed Node.js version, and which prints the npm version?
Show answer
node -v (or node --version) prints the Node.js version, for example v26.13.0. npm -v prints the npm version, for example 11.20.0.
Q2. Without creating a file, use node -p to print the result of 7 * 6.
Show answer
node -p "7 * 6"-p evaluates the expression and prints the result: 42. node -e runs code without printing the result, so you would need node -e "console.log(7 * 6)".
Q3. Write info.js that prints the Node.js version, the operating system and the CPU architecture on three lines.
Show answer
📄 info.js
console.log("Node:", process.version);
console.log("OS:", process.platform);
console.log("CPU:", process.arch);🖥️ Output
Node: v26.13.0
OS: win32
CPU: x64Q4. Add an npm script called hello that runs node info.js, then run it. What exactly do you type?
Show answer
npm pkg set scripts.hello="node info.js"
npm run helloOnly start and test can be run without the word run; every other script needs npm run <name>.
Q5. A teammate on Windows sees 'node' is not recognized as an internal or external command right after installing Node.js. List two likely causes and fixes.
Show answer
- The terminal was already open during the install, so it has the old PATH. Fix: close and reopen the terminal (and VS Code).
- “Add to PATH” was unticked in the installer. Fix: rerun the installer and keep it selected, or add
C:\Program Files\nodejs\to PATH.
Q6. Why is node --watch app.js useful while learning, and how do you stop it?
Show answer
Watch mode reruns the file automatically each time you save it, so you see the new output without typing the command again. Stop it with Ctrl+C.
🧠 MCQ Quiz: Install Node.js and VS Code
10 questions on this lesson. Pick one answer for each, then press Check answers to see your score and an explanation for every question.
- What does LTS stand for in Node.js releases?Answer: Long-Term Support. LTS releases receive fixes for about 30 months, which makes them the safe choice.
- Which Node.js line was the Active LTS in November 2026?Answer: Node.js 26. Node.js 26 (“Lithium”) is Active LTS; 27 is the Current pre-release and odd-numbered lines never become LTS.
- How do you install npm?Answer: It is installed automatically with Node.js. The Node.js installers and nvm include npm.
- What does
npm init -ycreate?Answer: Apackage.jsonfile with default values.-yaccepts every default answer and writespackage.json. - Which command runs a script named
devfrompackage.json?Answer:npm run dev. Custom scripts neednpm run; onlystartandtesthave shortcuts. - What does
node --watch app.jsdo?Answer: Rerunsapp.jswhenever the file changes. Watch mode is built into Node.js since version 18.11 and is stable in current versions. - Why might
brew install nodenot give you an LTS version?Answer: It installs the newest release line, which may be a Current release. Usebrew install node@26or nvm to stay on LTS. - Which VS Code shortcut opens the built-in terminal?Answer: Ctrl+`. Ctrl+Shift+X opens Extensions; F5 starts debugging.
- What is the most likely fix for
'node' is not recognizedright after installing?Answer: Close and reopen the terminal. Open terminals keep the old PATH until they are restarted. - What does
"type": "commonjs"inpackage.jsonmean?Answer:.jsfiles use the CommonJS module system (require). npm 11 adds this field by default."type": "module"would make.jsfiles ES modules.
💼 Interview Questions and Answers
Q1. What is Node.js, and how is it different from JavaScript?
JavaScript is the language. Node.js is a runtime that executes JavaScript outside the browser, built on the V8 engine plus libuv for asynchronous I/O. It adds APIs such as fs, http and process, and has no DOM. Test runners like Playwright and Jest run on Node.js.
Q2. Why should a test automation project pin its Node.js version, and how?
Different Node.js versions can change behaviour (for example module loading or built-in APIs), so CI and every laptop should use the same major version to avoid “works on my machine” failures. Pin it with an .nvmrc or .node-version file (for example 26), the "engines" field in package.json, and actions/setup-node with node-version-file in GitHub Actions.
Q3. What is the difference between npm, npx and nvm?
- npm installs packages and runs scripts from
package.json. - npx runs a package’s command without a global install, for example
npx playwright test. - nvm installs and switches between Node.js versions. It is not part of Node.js.
Q4. What is package.json used for?
It is the project manifest: name and version, scripts (named commands such as test), dependencies and devDependencies with version ranges, the module type ("type"), and the engines field. npm install reads it to install packages, and package-lock.json records the exact versions installed.
Q5. A CI job fails with “npm: command not found” but works locally. How do you investigate?
- Check that the job installs Node.js before using it (for example
actions/setup-nodeor a Docker image such asnode:26). - Print
node -vandnpm -vas the first step to confirm the versions. - If a version manager is used, make sure its shell setup is loaded in the CI shell (non-interactive shells may skip
~/.bashrc). - Pin the version with
.nvmrcso CI and local runs match.
❓ Frequently Asked Questions
🤔 Do I need to install JavaScript separately?
No. Browsers already include a JavaScript engine. To run JavaScript files on your computer you install Node.js, which includes the V8 engine and npm.
🤔 Which Node.js version should I install for Playwright?
Install the current LTS (Node.js 26 in November 2026). Playwright supports the active and maintenance LTS releases.
🤔 Can I use another editor instead of VS Code?
Yes. WebStorm, Sublime Text, Vim or any editor works. This course shows VS Code because it is free, popular and has the best JavaScript and Playwright extensions.
🤔 How do I update Node.js later?
Download the newer LTS installer and run it (it replaces the old version), run winget upgrade OpenJS.NodeJS.LTS on Windows, or with nvm run nvm install --lts and nvm alias default lts/*.
🏁 Summary
- You run JavaScript files with Node.js; npm comes with it. Always choose the LTS release (Node.js 26 in 2026).
- Install with the official installer, winget, Homebrew (
node@26) or nvm, then verify withnode -vandnpm -v. - A project is a folder with
package.json; create it withnpm init -yand add npm scripts. node --watchreruns your file on every save.- Configure VS Code with Prettier, ESLint, format on save and 2-space indentation.
Next, continue with Lesson 3: Run JavaScript: Console, REPL, Files.
🎬 Watch JavaScript and automation tutorials on YouTube!
Subscribe to SqaToolsByDY • Practice on sqatools.in