Introduction
Before you start writing JavaScript programs outside the browser or build automation scripts using frameworks like Playwright, Selenium WebDriver, or WebdriverIO, you need to install Node.js on your computer.
Node.js is a JavaScript runtime that allows JavaScript code to run outside a web browser. It also includes npm (Node Package Manager), which is used to install JavaScript libraries, frameworks, and tools required for development and automation testing.
Installing Node.js is the first step in setting up a JavaScript development and automation environment.
What is Node.js?
Node.js is an open-source, cross-platform JavaScript runtime built on Google’s V8 JavaScript engine.
It enables developers to:
-
Run JavaScript outside the browser
-
Build backend applications
-
Create REST APIs
-
Develop automation frameworks
-
Execute JavaScript scripts
-
Install third-party packages using npm
Why Do We Need Node.js?
Without Node.js, JavaScript can only run inside a web browser.
Node.js allows JavaScript to:
-
Access the file system
-
Connect to databases
-
Execute automation scripts
-
Create web servers
-
Install external libraries
-
Run command-line applications
Benefits of Installing Node.js
Installing Node.js provides:
-
JavaScript Runtime
-
npm (Node Package Manager)
-
Command Line Tools
-
Package Management
-
Cross-Platform Support
-
Access to Thousands of Open-Source Libraries
Node.js and npm
When you install Node.js, npm is installed automatically.
Node.js
Used to execute JavaScript programs.
npm
Used to:
-
Install packages
-
Update packages
-
Remove packages
-
Manage project dependencies
System Requirements
Before installing Node.js, ensure your system meets the following requirements:
-
Windows 10 or later
-
macOS
-
Linux
-
Administrator privileges (recommended)
-
Stable internet connection
Step 1: Download Node.js
-
Open your web browser.
-
Visit the official Node.js website.
-
Download the LTS (Long-Term Support) version.
-
Save the installer to your computer.
The LTS version is recommended because it is stable and suitable for most development and automation projects.
Step 2: Run the Installer
Locate the downloaded installer and double-click it.
The Node.js Setup Wizard will open.
Click:
Next
to continue.
Step 3: Accept the License Agreement
Read the license agreement.
Select:
I accept the terms in the License Agreement
Click:
Next
Step 4: Choose Installation Location
Select the installation folder.
The default location is usually sufficient.
Example:
C:\Program Files\nodejs\
Click:
Next
Step 5: Select Components
Keep the default components selected.
Typical components include:
-
Node.js Runtime
-
npm Package Manager
-
Online Documentation Shortcuts
-
Add to PATH
Click:
Next
Step 6: Install Node.js
Click:
Install
The installation process will begin.
Wait until the installation is completed.
Step 7: Finish Installation
Click:
Finish
Node.js is now installed on your computer.
Verify the Installation
Open:
-
Command Prompt
-
Windows Terminal
-
PowerShell
-
Terminal (macOS/Linux)
Check the installed Node.js version.
node -v
Example Output
v22.16.0
(The version number may differ depending on the latest release installed.)
Verify npm Installation
Check the npm version.
npm -v
Example Output
10.9.2
(The version number may vary.)
What Happens After Installation?
After installing Node.js, you can:
-
Execute JavaScript files
-
Install automation frameworks
-
Install third-party libraries
-
Create Node.js projects
-
Build web applications
-
Run automation scripts
Running Your First JavaScript Program
Create a file named:
app.js
Add the following code:
console.log("Hello, Node.js!");
Save the file.
Open the terminal in the same folder and run:
node app.js
Output
Hello, Node.js!
Congratulations! You have successfully executed your first JavaScript program using Node.js.
Checking the Installation Path
To verify where Node.js is installed, run:
Windows
where node
macOS/Linux
which node
The command displays the location of the Node.js executable.
Environment Variables
During installation, Node.js is automatically added to the system’s PATH environment variable.
This allows you to run Node.js commands from any directory.
Example:
node app.js
You do not need to navigate to the installation folder to execute Node.js commands.
Installing Packages Using npm
Once Node.js is installed, you can install packages easily.
Example:
npm install playwright
Another example:
npm install axios
These packages are downloaded and added to your project.
Common Commands After Installation
| Command | Description |
|---|---|
node -v |
Displays the installed Node.js version |
npm -v |
Displays the npm version |
node app.js |
Runs a JavaScript file |
npm init |
Creates a new Node.js project |
npm install package-name |
Installs a package |
npm uninstall package-name |
Removes a package |
Common Installation Problems
Node Command Not Recognized
Error
'node' is not recognized as an internal or external command.
Solution
-
Restart the terminal.
-
Restart the computer.
-
Ensure Node.js was added to the system PATH.
-
Reinstall Node.js if necessary.
npm Command Not Found
Solution
Verify that npm was installed correctly.
Run:
npm -v
If npm is missing, reinstall Node.js.
Installing the Wrong Version
Avoid installing experimental versions unless required.
Use the LTS (Long-Term Support) version for stability.
Best Practices
Install the LTS Version
The LTS version is stable, well-tested, and recommended for development and automation projects.
Verify the Installation
Always check both Node.js and npm versions after installation.
node -v
npm -v
Keep Node.js Updated
Update Node.js periodically to receive:
-
Performance improvements
-
Security updates
-
New features
-
Bug fixes
Use npm for Dependency Management
Instead of downloading libraries manually, install them using npm.
Example:
npm install playwright
Real-World Example
Suppose you want to automate a login page using Playwright.
The first step is to install Node.js.
After installation, you can:
-
Create a project.
-
Install Playwright using npm.
-
Write JavaScript automation scripts.
-
Execute tests using Node.js.
Without Node.js, these automation scripts cannot run.
Conclusion
Installing Node.js is the foundation of JavaScript development and automation testing. It provides the JavaScript runtime needed to execute programs outside the browser and includes npm for managing libraries and dependencies.
Whether you are developing web applications, creating automation frameworks, or writing API tests, Node.js is an essential tool. By installing the LTS version, verifying the installation, and understanding basic Node.js commands, you are ready to begin your JavaScript development and automation journey.
Frequently Asked Questions (FAQs)
What is Node.js?
Node.js is a JavaScript runtime that allows JavaScript code to run outside a web browser.
Does Node.js include npm?
Yes. npm (Node Package Manager) is installed automatically with Node.js.
Which Node.js version should I install?
It is recommended to install the LTS (Long-Term Support) version.
How do I verify that Node.js is installed?
Run:
node -v
Can I run JavaScript without Node.js?
Yes, JavaScript can run inside a web browser. However, to execute JavaScript outside the browser or use automation frameworks like Playwright, Selenium WebDriver (JavaScript), or WebdriverIO, Node.js is required.
Key Takeaways
-
Node.js is a JavaScript runtime used to execute JavaScript outside the browser.
-
npm is installed automatically with Node.js.
-
The LTS version is recommended for development and automation projects.
-
Verify the installation using
node -vandnpm -v. -
Node.js enables JavaScript development, backend programming, and automation testing.
-
npm simplifies installing and managing project dependencies.
-
Node.js adds the
nodecommand to the system PATH. -
Automation frameworks such as Playwright and WebdriverIO require Node.js.
-
Installing Node.js is the first step in setting up a JavaScript development environment.
-
A correctly installed Node.js environment prepares you for building modern JavaScript applications and automation frameworks.
