Node.js is a popular JavaScript runtime that lets you run JavaScript code outside of a browser, commonly used for server-side development. Here’s how to install it on Windows:
Node.js is a powerful runtime environment for executing JavaScript on the server-side. Here’s a detailed guide to installing and using Node.js on Windows.
Why Use Node.js?
- Enables server-side scripting in JavaScript.
- Non-blocking I/O for building scalable and efficient applications.
- Extensive library ecosystem via npm (Node Package Manager).
1. Download Node.js Installer – Node.js on Windows 11 and Windows 10
- Visit the official Node.js website.
- You’ll see two versions available for download:
- LTS (Long Term Support): Recommended for most users, especially for production use.
- Current: Includes the latest features but may not be as stable.
- Click the appropriate version for your system. The website automatically detects whether your system is 32-bit or 64-bit.
2. Run the Installer on Windows 11 and Windows 10
- Locate the downloaded file (e.g.,
node-vXX.X.X-x64.msi
) and Node.js on Windowsdouble-click it to launch the installer. - Follow the setup wizard:
- Click Next to proceed with the installation.
- Read and accept the License Agreement, then click Next.
- Choose an installation folder or use the default path (recommended).
3. Choose Components
- The installer will let you choose components to install:
- Node.js runtime: The core runtime for running JavaScript.
- npm package manager: Installed by default with Node.js.
- Add to PATH: Ensures that Node.js and npm can be used from the command line (this is usually selected by default).
- Optionally, select tools for native modules.
Click Next after confirming your choices.
4. Install Additional Tools (Optional) Node.js on Windows
- During installation, the wizard may prompt you to install additional tools for native modules (e.g., Python and Visual Studio Build Tools).
- Check the box if you plan to work with Node.js modules requiring compilation, then click Next.
5. Complete the Installation
- Click Install to begin the installation process.
- After the installation is complete, click Finish to close the setup wizard.
6. Verify Installation
- Open the Command Prompt or PowerShell.
- Type the following commands to check if Node.js and npm were installed successfully:
- Check Node.js version:
node -v
This should display the installed version of Node.js. - Check npm version:
npm -v
This should display the installed version of npm.
- Check Node.js version:
7. Update npm (Optional) Node.js on Windows
To ensure you have the latest version of npm:
npm install -g npm
8. Test Your Installation
- Create a simple Node.js app:
- Create a new file called
app.js
with the following content:console.log("Hello, Node.js!");
- Save the file.
- Create a new file called
- Run the app:
- Open the Command Prompt.
- Navigate to the folder where
app.js
is saved. - Run the file using:
node app.js
- If installed correctly, you’ll see
Hello, Node.js!
printed in the console.
9. Install Node.js Packages /Node.js on Windows 11
- Use npm to install packages globally or locally:
- Example of installing a package globally:
npm install -g nodemon
- Example of installing a package locally:
npm install express
- Example of installing a package globally:
10. Troubleshooting
If you encounter issues:
- Ensure Node.js is added to your PATH:
- Go to Control Panel > System > Advanced System Settings > Environment Variables.
- Look for
PATH
under System Variables and ensure it includes the path to Node.js (e.g.,C:\Program Files\nodejs
).
- Restart your terminal to apply changes.
Using Node.js on Windows
1. Writing Your First Node.js Program
- Open a text editor and create a file named
app.js
. - Add the following code:javascriptCopy code
console.log("Hello, Node.js!");
- Save the file in a folder, e.g.,
C:\NodeProjects
.
2. Run the Program
- Open Command Prompt.
- Navigate to the folder where
app.js
is saved:bashCopy codecd C:\NodeProjects
- Run the program:bashCopy code
node app.js
Output:Hello, Node.js!
Installing Node.js Packages
- npm allows you to install packages for Node.js applications.
Global Installation
Global packages can be used across projects.
bashCopy codenpm install -g nodemon
Local Installation
Install packages in the current project directory.
bashCopy codenpm install express
List Installed Packages
- Local packages:bashCopy code
npm list
- Global packages:bashCopy code
npm list -g --depth=0
Updating Node.js and npm
- Update npm:bashCopy code
npm install -g npm
- Update Node.js:
- Download the latest version from the Node.js website and reinstall it.
Troubleshooting Common Issues
1. PATH Issues
If node
or npm
commands aren’t recognized:
- Check if Node.js is in your PATH.
- Go to Control Panel > System > Advanced System Settings > Environment Variables.
- Look for
PATH
and ensure it includes the directory of Node.js (e.g.,C:\Program Files\nodejs
).
- Restart your terminal after making changes.
2. Permissions Errors
Run the terminal as an administrator when installing global npm packages.
Next Steps
- Explore Node.js frameworks like:
- Express.js: For building web applications.
- Socket.io: For real-time communication.
- Learn asynchronous programming with
Promises
andasync/await
. - Build a RESTful API.
How to Download Node JS for Windows 11 and Window 10
Node js download for windows 11
Node js download for windows 10
Nest JS and PgSQL Database connectivity
Now you’re ready to start developing with Node.js on your Windows machine! Let me know if you need help with anything else.