Skip to main content

Node.js Environment Setup - Installation and Configuration Guide

Setting up Node.js on your system is the first step to start developing server-side JavaScript applications. This comprehensive guide will walk you through installing Node.js on different operating systems and configuring your development environment.

System Requirements

Before installing Node.js, ensure your system meets the minimum requirements:

Supported Operating Systems

  • Windows: Windows 10 or later (64-bit recommended)
  • macOS: macOS 10.15 (Catalina) or later
  • Linux: Ubuntu 18.04+, CentOS 7+, Debian 9+, or equivalent

Hardware Requirements

  • RAM: Minimum 512MB, recommended 1GB or more
  • Storage: At least 200MB free space
  • Processor: Any modern processor (x64 architecture recommended)

Installation Methods

The easiest way to install Node.js is using the official installer from the Node.js website.

Windows Installation

  1. Download the Installer

    • Visit nodejs.org
    • Download the LTS (Long Term Support) version
    • Choose the Windows Installer (.msi) for your system architecture
  2. Run the Installer

    # The installer will guide you through the process
    # Make sure to check "Add to PATH" option
  3. Verify Installation

    node --version
    npm --version

macOS Installation

  1. Download the Installer

    • Visit nodejs.org
    • Download the macOS Installer (.pkg)
  2. Install Node.js

    # Double-click the .pkg file and follow the installer
    # The installer will automatically add Node.js to your PATH
  3. Verify Installation

    node --version
    npm --version

Linux Installation

  1. Download the Installer

    # Download the Linux binary
    wget https://nodejs.org/dist/v18.17.0/node-v18.17.0-linux-x64.tar.xz
  2. Extract and Install

    # Extract the archive
    tar -xf node-v18.17.0-linux-x64.tar.xz

    # Move to /usr/local
    sudo mv node-v18.17.0-linux-x64 /usr/local/nodejs

    # Add to PATH
    echo 'export PATH=/usr/local/nodejs/bin:$PATH' >> ~/.bashrc
    source ~/.bashrc
  3. Verify Installation

    node --version
    npm --version

Method 2: Package Managers

Using Homebrew (macOS)

# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Node.js
brew install node

# Verify installation
node --version
npm --version

Using APT (Ubuntu/Debian)

# Update package index
sudo apt update

# Install Node.js
sudo apt install nodejs npm

# Verify installation
node --version
npm --version

Using YUM (CentOS/RHEL)

# Install Node.js
sudo yum install nodejs npm

# Or for newer versions
sudo dnf install nodejs npm

# Verify installation
node --version
npm --version

Method 3: Node Version Manager (NVM)

NVM allows you to install and manage multiple Node.js versions.

Install NVM

Linux/macOS:

# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# Reload shell configuration
source ~/.bashrc
# or
source ~/.zshrc

Windows:

# Install nvm-windows
# Download from: https://github.com/coreybutler/nvm-windows/releases

Using NVM

# List available Node.js versions
nvm list-remote

# Install latest LTS version
nvm install --lts

# Install specific version
nvm install 18.17.0

# Use specific version
nvm use 18.17.0

# Set default version
nvm alias default 18.17.0

# List installed versions
nvm list

Verification and Testing

Check Node.js Installation

# Check Node.js version
node --version
# Output: v18.17.0

# Check npm version
npm --version
# Output: 9.6.7

# Check installation path
which node
# Output: /usr/local/bin/node (Linux/macOS)
# Output: C:\Program Files\nodejs\node.exe (Windows)

Test Node.js Installation

Create a test file test.js:

// test.js
console.log('Node.js is working correctly!');
console.log('Node.js version:', process.version);
console.log('Platform:', process.platform);
console.log('Architecture:', process.arch);
console.log('Current directory:', process.cwd());
console.log('Environment:', process.env.NODE_ENV || 'development');

Run the test:

node test.js

Expected output:

Node.js is working correctly!
Node.js version: v18.17.0
Platform: linux
Architecture: x64
Current directory: /home/user/projects
Environment: development

NPM Configuration

Global vs Local Packages

# Install package globally
npm install -g package-name

# Install package locally (in current project)
npm install package-name

# Install package as dev dependency
npm install --save-dev package-name

NPM Configuration

# Set default registry
npm config set registry https://registry.npmjs.org/

# Set proxy (if needed)
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

# View current configuration
npm config list

# Edit npm configuration
npm config edit

NPM Cache Management

# Clear npm cache
npm cache clean --force

# Verify cache
npm cache verify

# View cache location
npm config get cache

Environment Variables

Important Node.js Environment Variables

# Node.js environment
export NODE_ENV=development # or production
export NODE_PATH=/usr/local/lib/node_modules

# NPM configuration
export NPM_CONFIG_PREFIX=/usr/local
export NPM_CONFIG_CACHE=/tmp/.npm

# Path configuration
export PATH=$PATH:/usr/local/bin

Setting Environment Variables

Linux/macOS:

# Add to ~/.bashrc or ~/.zshrc
echo 'export NODE_ENV=development' >> ~/.bashrc
source ~/.bashrc

Windows:

# Set environment variable
set NODE_ENV=development

# Or permanently
setx NODE_ENV development

IDE and Editor Setup

Visual Studio Code

  1. Install VS Code

  2. Install Node.js Extensions

    • Node.js Extension Pack
    • JavaScript (ES6) code snippets
    • npm Intellisense
    • Node.js Modules Intellisense
  3. Configure VS Code

    // .vscode/settings.json
    {
    "nodejs.detectPnpm": true,
    "npm.packageManager": "npm",
    "javascript.preferences.includePackageJsonAutoImports": "auto",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
    }
    }

WebStorm:

  • Built-in Node.js support
  • Integrated terminal and debugger
  • NPM integration

Sublime Text:

  • Install Node.js packages via Package Control
  • Configure build systems for Node.js

Atom:

  • Install Node.js packages
  • Configure build tools

Troubleshooting Common Issues

Issue 1: Command Not Found

Problem: node: command not found or npm: command not found

Solutions:

# Check if Node.js is in PATH
echo $PATH

# Add Node.js to PATH (Linux/macOS)
export PATH=$PATH:/usr/local/bin

# Restart terminal or reload shell configuration
source ~/.bashrc

Issue 2: Permission Errors

Problem: Permission denied when installing global packages

Solutions:

# Use npm with sudo (not recommended)
sudo npm install -g package-name

# Configure npm to use different directory
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

Issue 3: Version Conflicts

Problem: Multiple Node.js versions installed

Solutions:

# Use NVM to manage versions
nvm use 18.17.0

# Or uninstall conflicting versions
# Windows: Use Add/Remove Programs
# Linux: sudo apt remove nodejs npm
# macOS: brew uninstall node

Issue 4: Network/Proxy Issues

Problem: Cannot download packages due to network restrictions

Solutions:

# Configure npm proxy
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

# Use different registry
npm config set registry https://registry.npmmirror.com/

# Disable SSL verification (not recommended for production)
npm config set strict-ssl false

Best Practices

Version Management

# Use LTS versions for production
nvm install --lts
nvm use --lts

# Keep npm updated
npm install -g npm@latest

# Use .nvmrc file for project-specific versions
echo "18.17.0" > .nvmrc
nvm use

Security Considerations

# Audit packages for vulnerabilities
npm audit

# Fix vulnerabilities
npm audit fix

# Use npm ci for production builds
npm ci

# Lock dependency versions
npm shrinkwrap

Performance Optimization

# Use npm cache
npm config set cache /tmp/.npm

# Increase network timeout
npm config set timeout 60000

# Use parallel installation
npm install --prefer-offline --no-audit

Development Environment Setup

Project Structure

# Create a new Node.js project
mkdir my-nodejs-project
cd my-nodejs-project

# Initialize package.json
npm init -y

# Install common dependencies
npm install express
npm install --save-dev nodemon

# Create basic project structure
mkdir src
mkdir tests
touch src/index.js
touch README.md

Package.json Configuration

{
"name": "my-nodejs-project",
"version": "1.0.0",
"description": "My Node.js project",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js",
"dev": "nodemon src/index.js",
"test": "jest"
},
"keywords": ["nodejs", "express"],
"author": "Your Name",
"license": "MIT"
}

Next Steps

Now that you have Node.js installed and configured, you're ready to:

  1. Node.js - First Application - Build your first Node.js application
  2. Node.js - REPL Terminal - Learn the interactive Node.js shell
  3. Node.js - Package Manager (NPM) - Master package management
  4. Node.js - Command Line Options - Learn CLI parameters

Environment Setup Complete! You now have Node.js properly installed and configured. Ready to start building applications!