Fullstack > Tools > ⚡ Node.js
NodeJS
Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. It allows developers to build scalable and fast web applications. This guide will help you install Node.js on your system.
Step 1: Download Node.js
- Go to the official Node.js Download page.
- Choose the LTS (Long Term Support) version for stability or the Current version for the latest features.
- Download the installer suitable for your operating system (Windows, macOS, or Linux).
Step 2: Install Node.js
On Windows:
- Run the downloaded
.msifile. - Follow the installation wizard and complete the setup.
- Verify the installation by running the following commands in Command Prompt:
node -v npm -v
On macOS:
- Run the downloaded
.pkgfile and follow the installation instructions. - Verify installation:
node -v npm -v
On Linux (Using Package Manager):
Ubuntu/Debian:
- Open the terminal and run:
sudo apt update sudo apt install nodejs npm - Verify installation:
node -v npm -v
Using Node Version Manager (NVM):
- Install NVM:
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash - Close and reopen the terminal, then install Node.js:
nvm install --lts - Verify installation:
node -v npm -v
Step 3: Set Up NODE_HOME Environment Variable
Setting up the NODE_HOME variable ensures proper Node.js configuration.
On Windows:
- Open System Properties > Advanced > Environment Variables.
- Add a new system variable:
- Variable name: NODE_HOME
- Variable value: Path to Node.js installation (e.g.,
C:\Program Files\nodejs)
On macOS and Linux:
- Open the terminal and edit your profile file:
nano ~/.bashrc # or ~/.zshrc - Add the following line:
export NODE_HOME=$(dirname $(dirname $(which node))) - Apply changes:
source ~/.bashrc
Step 4: Verify Installation
Run the following command to check if Node.js and npm are correctly installed:
node -v
npm -v
Step 5: Run an Example Node.js Program
- Open a text editor and create a new file named
app.js. - Copy and paste the following Node.js code:
console.log("Hello, Node.js!"); - Save the file and navigate to the directory where it is saved using the terminal or command prompt.
- Run the program using:
node app.js - You should see the output:
Hello, Node.js!
Conclusion
You have successfully installed Node.js on your system! You can now start building server-side applications using JavaScript.