DEV Community

Cover image for How to Install Node.js: A Step-by-Step Guide
surendra sahu
surendra sahu

Posted on

How to Install Node.js: A Step-by-Step Guide

Node.js is a powerful runtime environment that allows developers to run JavaScript on the server side. Whether you're a beginner or an experienced developer, installing Node.js correctly is crucial. In this guide, we'll walk through the installation process for Windows, macOS, and Linux, along with verifying the installation and setting up a basic project.

Why Use Node.js?

Node.js is widely used for backend development, real-time applications, APIs, and more. Some benefits include:

  • Non-blocking, event-driven architecture.
  • High performance due to the V8 JavaScript engine.
  • Large ecosystem with npm (Node Package Manager).

Installing Node.js on Windows

Step 1: Download the Installer

  1. Visit the official Node.js download page.
  2. Choose the LTS (Long-Term Support) version for stability.
  3. Download the Windows Installer (.msi file).

Step 2: Run the Installer

  1. Open the downloaded .msi file.
  2. Follow the installation wizard and accept the terms.
  3. Select the default settings and complete the installation.

Step 3: Verify the Installation

Open Command Prompt (Win + R, type cmd, and press Enter) and run:

node -v
Enter fullscreen mode Exit fullscreen mode

This should display the installed Node.js version. Also, verify npm (Node Package Manager) with:

npm -v
Enter fullscreen mode Exit fullscreen mode

Installing Node.js on macOS

Step 1: Use Homebrew (Recommended)

If you donโ€™t have Homebrew, install it first by running:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Then, install Node.js with:

brew install node
Enter fullscreen mode Exit fullscreen mode

Step 2: Verify Installation

Check the versions:

node -v
npm -v
Enter fullscreen mode Exit fullscreen mode

Installing Node.js on Linux

Step 1: Update the System Packages

sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Node.js using apt

sudo apt install nodejs npm -y
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify Installation

node -v
npm -v
Enter fullscreen mode Exit fullscreen mode

Installing Node.js via Node Version Manager (NVM)

Using NVM is the best way to manage multiple Node.js versions.

Step 1: Install NVM

curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

Restart the terminal and verify the installation:

command -v nvm
Enter fullscreen mode Exit fullscreen mode

Step 2: Install and Use Node.js

nvm install --lts
nvm use --lts
Enter fullscreen mode Exit fullscreen mode

Creating a Simple Node.js Project

Let's create a basic Node.js application.

Step 1: Initialize a New Project

mkdir my-node-app
cd my-node-app
npm init -y
Enter fullscreen mode Exit fullscreen mode

This creates a package.json file, which manages the project dependencies.

Step 2: Create an index.js File

Inside the project folder, create index.js and add:

console.log("Hello, Node.js!");
Enter fullscreen mode Exit fullscreen mode

Step 3: Run the Script

node index.js
Enter fullscreen mode Exit fullscreen mode

It should output:

Hello, Node.js!
Enter fullscreen mode Exit fullscreen mode

Conclusion

Now, you've successfully installed Node.js on your system and created a simple project. If youโ€™re working on enterprise-level applications, integrating different systems is crucial. Check out our System Integration Services to streamline your development workflow efficiently.

Node.js provides a vast ecosystem for building scalable applications. Keep exploring and happy coding!

Top comments (0)