Introduction
Node.js is a powerful, open-source JavaScript runtime that allows developers to run JavaScript outside the browser. It is widely used for building scalable web applications and server-side scripting. If you are a developer working in a Software Development Company, installing Node.js on Windows is an essential step to start with modern web development. This guide will walk you through the installation process step-by-step, ensuring a smooth setup.
Prerequisites
Before we begin, ensure that you have the following:
- A Windows operating system (Windows 10 or later recommended)
- Administrator privileges to install software
- An active internet connection
Step 1: Download Node.js Installer
- Open a web browser and go to the official Node.js website: https://nodejs.org
- You will see two versions available for download:
- LTS (Long-Term Support): Recommended for most users, especially for production environments.
- Current: Includes the latest features but may not be as stable as LTS.
- Click on the Windows Installer (.msi) file for the LTS version.
Step 2: Run the Installer
- Once the download is complete, locate the downloaded
.msi
file in your Downloads folder. - Double-click the file to start the installation.
- A setup wizard will appear. Click Next to proceed.
Step 3: Accept the License Agreement
- Read the license agreement and click I accept the terms in the License Agreement.
- Click Next.
Step 4: Choose Installation Path
- The default installation path is usually
C:\Program Files\nodejs\
. - You can change the location if needed or keep the default path and click Next.
Step 5: Select Components
- The installer provides an option to select components:
- Node.js runtime (Required)
- npm package manager (Recommended)
- Add to PATH (Highly recommended)
- Keep all options selected and click Next.
Step 6: Install Node.js
- Click Install to begin the installation process.
- Wait for the installation to complete. This may take a few minutes.
- Once done, click Finish to exit the setup.
Step 7: Verify Installation
To ensure that Node.js and npm are installed correctly, open the Command Prompt (Press Win + R
, type cmd
, and press Enter
) and run the following commands:
Check Node.js Version
node -v
You should see an output similar to:
v18.16.0
Check npm Version
npm -v
You should see an output like:
9.5.1
If both commands return a version number, the installation was successful.
Step 8: Set Up a Simple Node.js Application
Now that Node.js is installed, let’s create a simple Node.js application.
- Open a terminal and create a new directory:
mkdir my-node-app cd my-node-app
- Initialize a new Node.js project:
npm init -y
This creates apackage.json
file. - Create a new JavaScript file:
echo "console.log('Hello, Node.js!');" > app.js
- Run the Node.js script:
node app.js
Output:Hello, Node.js!
Common Issues and Fixes
1. ‘node’ is not recognized as an internal or external command
Solution:
- Restart your computer to ensure the PATH variable is updated.
- Manually add Node.js to the PATH:
- Open System Properties (
Win + Pause
→ Advanced system settings → Environment Variables). - Under System Variables, find
Path
and click Edit. - Add
C:\Program Files\nodejs\
to the list and click OK.
- Open System Properties (
2. npm ERR! code ECONNRESET
Solution:
- Check your internet connection.
- Try running:
npm cache clean --force
- If the issue persists, use a VPN or change the npm registry:
npm config set registry https://registry.npmjs.org/
Conclusion
Installing Node.js on Windows is straightforward if you follow these steps. Whether you are an individual developer or working in a Software Development Company, Node.js is a crucial tool for modern web development. By following this guide, you have successfully installed Node.js, verified the installation, and created your first simple application.
Now that you have Node.js up and running, you can explore frameworks like Express.js for building web applications or use Node.js for server-side scripting. Happy coding!