Verify Node.js Installation
Learn how to verify the Node.js runtime, check npm, execute JavaScript code, inspect environment configuration, and troubleshoot common installation problems.
1. Introduction to Installation Verification
After installing Node.js, we should verify that the installation works correctly. Installation verification means checking whether the Node.js runtime and npm commands are available and functioning as expected.
Sometimes a program may be installed on a computer but may not be accessible from the terminal because of a PATH configuration problem. Verification helps us identify these problems before starting application development.
What Should We Verify?
| Component | Verification | Purpose |
|---|---|---|
| Node.js | node --version |
Checks the installed runtime version. |
| npm | npm --version |
Checks npm command availability. |
| Executable Path | where node |
Checks where Windows finds Node.js. |
| JavaScript Execution | node app.js |
Confirms that Node.js can execute a file. |
2. Node.js Installation Verification Workflow
Follow the verification process in sequence. If one step fails, resolve the issue before moving to the next step.
3. Check the Node.js Version
The first step is to verify whether the Node.js command is available in the terminal.
Step 1: Open Command Prompt or Terminal
Open Command Prompt, PowerShell, or your code editor's integrated terminal.
Step 2: Execute the Command
node --version
Explanation
nodeinvokes the Node.js executable.--versionrequests the installed version.- The command does not execute a project file.
Expected Output
v22.x.x
The version shown above is an example. Your computer may display a different version depending on your installation.
4. Check the npm Version
npm is the package manager commonly used with Node.js. It helps us install packages, maintain dependency information, and run commands defined in a project's configuration.
Step 1: Execute the npm Version Command
npm --version
Expected Output
10.x.x
This is illustrative output. The actual npm version may be different on your computer.
What Does This Confirm?
- The terminal can locate the npm command.
- npm can start and report its version.
- You can proceed to test basic project commands.
5. Verify the Node.js Executable Path
The PATH environment variable helps the operating system find executable commands. Checking the executable path can help troubleshoot installation problems.
Step 1: Find the Node.js Executable
where node
Example Output
C:\Program Files\nodejs\node.exe
This is an example path. Your installation may use a different location.
Step 2: Find the npm Command
where npm
Windows displays the locations it can find for the npm command. If multiple locations appear, check that your environment is using the intended Node.js installation.
where command is intended for Windows Command
Prompt. Other terminals and operating systems may use different
commands to inspect executable locations.
6. Test JavaScript Execution
Checking the version confirms that the command runs. The next step is to execute an actual JavaScript file.
Step 1: Create a Test File
Create a file named verify.js in a project folder.
Add the following code:
console.log("Node.js installation verified.");
console.log("JavaScript execution is working.");
const result = 10 + 20;
console.log("Result:", result);
Step 2: Execute the File
node verify.js
Expected Output
Node.js installation verified.
JavaScript execution is working.
Result: 30
Code Explanation
| Statement | Explanation |
|---|---|
console.log() |
Displays a message in the terminal. |
const result = 10 + 20; |
Adds two numbers and stores the result. |
console.log("Result:", result); |
Displays the label and calculated value. |
7. Installation Troubleshooting Flow
If a verification command fails, use this flow to identify the next troubleshooting step.
node --version
Yes
Run npm --version and then execute
a JavaScript test file.
No
Check the Node.js installation, terminal session, and PATH configuration.
node verify.js
8. Common Verification Errors
| Error | Possible Reason | Solution |
|---|---|---|
| Node.js is not recognized | Node.js is missing or PATH is not configured. | Verify the installation and PATH, then reopen the terminal. |
| npm is not recognized | npm is not available in the current environment. | Check the installation and run npm --version again. |
| Cannot find verify.js | The terminal is in the wrong folder or the file is missing. | Check the filename and current directory. |
| Syntax error | The JavaScript code contains invalid syntax. | Check quotation marks, brackets, and spelling. |
| Unexpected output | The file may contain different code. | Save the file and execute it again. |
9. CIIT Training Institute - Practice Task
Task: Verify Your Node.js Environment
- Open a terminal.
- Run
node --version. - Run
npm --version. - Check the executable location using
where nodeon Windows. - Create a file named
testEnvironment.js. - Print a welcome message using
console.log(). - Calculate the sum of two numbers.
- Execute the file using Node.js.
- Compare the terminal output with your expected result.
Expected Result
Welcome to CIIT Training Institute!
Node.js verification completed.
Sum: 50
Your output should match the messages in the example if you use the corresponding statements in your JavaScript file.
Summary
Node.js installation verification confirms that the Node.js runtime and npm commands are working correctly. We checked version numbers, inspected executable paths, and executed a JavaScript file to verify the environment. Understanding PATH configuration and common errors helps developers troubleshoot installation problems. Practical exercises at CIIT TRAINING INSTITUTE help students build a strong foundation for Node.js development.