Skip to main content
README.md 13.46 KB

Node.js Complete Guide: Download, Install & Getting Started

πŸ“‹ Table of Contents

1. What is Node.js? 2. System Requirements 3. Download Options 4. Installation Guides 5. Getting Started 6. Working with Node.js 7. Development Tools 8. Troubleshooting 9. Additional Resources

πŸ“– What is Node.js?

Node.js is an open-source, cross-platform JavaScript runtime environment that allows developers to execute JavaScript code outside of a web browser. It's built on Chrome's V8 JavaScript engine and uses an event-driven, non-blocking I/O model, making it efficient for building scalable network applications.

Key Features:

  • JavaScript on the server: Run JavaScript on your computer/server
  • NPM (Node Package Manager): Largest ecosystem of open-source libraries
  • Asynchronous and event-driven: Handles multiple connections efficiently
  • Cross-platform: Works on Windows, macOS, and Linux
  • Single-threaded with event looping: Efficient for I/O-intensive applications
  • πŸ–₯️ System Requirements

    Minimum Requirements:

  • RAM: At least 512 MB (1 GB+ recommended)
  • Disk Space: 200 MB free space
  • Operating Systems:
  • Windows: 8.1, 10, 11 (64-bit recommended)
  • macOS: 10.15 (Catalina) or later
  • Linux: Most modern distributions
  • Recommended for Development:

  • RAM: 4 GB or more
  • Processor: Modern multi-core CPU
  • Disk Space: 1 GB+ for projects and dependencies
  • πŸ“₯ Download Options

    Official Download Page:

    https://nodejs.org

    Version Choices:

    | Version Type | Description | Recommended For | |-------------|-------------|-----------------| | LTS (Long Term Support) | Stable, production-ready version with long-term support | Production applications, enterprise use | | Current | Latest features, more frequent updates | Development, testing new features |

    Direct Download Links:

  • Windows: .msi installer (64-bit/32-bit)
  • macOS: .pkg installer
  • Linux: Binaries (.tar.xz) or via package manager
  • Source Code: Compile from source if needed
  • πŸ”§ Installation Guides

    Method 1: Direct Installer (Simplest)

    **Windows Installation:**

    1. Download the Windows installer (.msi) from nodejs.org 2. Double-click the downloaded file 3. Follow the installation wizard 4. Check "Automatically install the necessary tools" for npm and build tools 5. Click "Install" 6. Verify installation:

    BASH
    1
    2
       node --version
    

    npm --version

    **macOS Installation:**

    1. Download the macOS installer (.pkg) 2. Open the downloaded file 3. Follow the installation instructions 4. Verify installation in Terminal:

    BASH
    1
    2
       node --version
    

    npm --version

    **Linux Installation (Ubuntu/Debian):**

    BASH
    1
    2
    3
    4
    # Using NodeSource repository (recommended)
    

    curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs

    # Or using APT (may have older version) sudo apt update sudo apt install nodejs npm

    # Verify installation node --version npm --version

    Method 2: Using NVM (Node Version Manager) - **Recommended for Developers**

    NVM allows you to install and switch between multiple Node.js versions.

    **Install NVM:**

    Windows:

    BASH
    1
    2
    # Download and run the nvm-setup.exe from:
    

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

    macOS/Linux:

    BASH
    1
    2
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
    

    # After installation, either restart terminal or run: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

    **Using NVM:**

    BASH
    1
    2
    3
    4
    5
    6
    # List available Node.js versions
    

    nvm list available

    # Install specific version nvm install 20.14.0 # Specific version nvm install --lts # Latest LTS version nvm install node # Latest current version

    # List installed versions nvm list

    # Use a specific version nvm use 20.14.0

    # Set default version nvm alias default 20.14.0

    Method 3: Package Managers

    **macOS (Homebrew):**

    BASH
    1
    brew install node

    **Linux (Various Distributions):**

    BASH
    1
    2
    3
    4
    # Fedora
    

    sudo dnf install nodejs npm

    # Arch Linux sudo pacman -S nodejs npm

    # Snap (Universal) sudo snap install node --classic

    πŸš€ Getting Started

    Your First Node.js Application

    1. Create a project directory:

    BASH
    1
    2
       mkdir my-first-app
    

    cd my-first-app

    2. Initialize a new Node.js project:

    BASH
    1
       npm init -y

    This creates a package.json file with default settings.

    3. Create your first JavaScript file:

    BASH
    1
       echo 'console.log("Hello, Node.js!");' > app.js

    4. Run your application:

    BASH
    1
    2
       node app.js
    

    # Output: Hello, Node.js!

    Understanding `package.json`

    When you run npm init, it creates a package.json file:

    JSON
    1
    2
    {
    

    "name": "my-first-app", "version": "1.0.0", "description": "My first Node.js application", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node app.js" }, "keywords": [], "author": "Your Name", "license": "ISC" }

    Running Your Application

    BASH
    1
    2
    3
    4
    # Direct execution
    

    node app.js

    # Using npm script (defined in package.json) npm start

    # For development with auto-restart (install nodemon first) npm install -g nodemon nodemon app.js

    πŸ› οΈ Working with Node.js

    Core Modules (Built-in)

    Node.js comes with essential modules you can use without installation:

    JAVASCRIPT
    1
    2
    3
    4
    5
    // File System module
    

    const fs = require('fs'); fs.readFile('file.txt', 'utf8', (err, data) => { if (err) throw err; console.log(data); });

    // HTTP module (create web servers) const http = require('http'); http.createServer((req, res) => { res.writeHead(200, {'Content-Type': 'text/html'}); res.end('Hello World!'); }).listen(8080);

    // Path module const path = require('path'); console.log(path.join(__dirname, 'folder', 'file.txt'));

    // OS module const os = require('os'); console.log(`Platform: ${os.platform()}`); console.log(`CPU Cores: ${os.cpus().length}`);

    Working with NPM (Node Package Manager)

    Installing Packages:

    BASH
    1
    2
    3
    4
    5
    # Install locally (for current project)
    

    npm install package-name

    # Install globally (available system-wide) npm install -g package-name

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

    # Install specific version npm install [email protected]

    Common NPM Commands:

    BASH
    1
    2
    3
    4
    5
    6
    7
    8
    # Initialize new project
    

    npm init

    # Install all dependencies from package.json npm install

    # Update packages npm update package-name npm update --save

    # Uninstall packages npm uninstall package-name

    # List installed packages npm list npm list --depth=0 # Show only top-level

    # Check for outdated packages npm outdated

    # Run scripts npm run script-name

    Creating a Web Server

    JAVASCRIPT
    1
    2
    3
    4
    5
    // server.js
    

    const http = require('http');

    const server = http.createServer((req, res) => { // Set response header res.writeHead(200, {'Content-Type': 'text/html'});

    // Send response based on URL if (req.url === '/') { res.end('<h1>Home Page</h1><p>Welcome to Node.js!</p>'); } else if (req.url === '/about') { res.end('<h1>About Page</h1>'); } else { res.writeHead(404); res.end('<h1>404 Not Found</h1>'); } });

    // Start server on port 3000 const PORT = 3000; server.listen(PORT, () => { console.log(`Server running at http://localhost:${PORT}/`); });

    Run with: node server.js

    Working with Express.js (Popular Web Framework)

    1. Install Express:

    BASH
    1
       npm install express

    2. Create an Express app:

    JAVASCRIPT
    1
    2
    3
    4
    5
       // app.js
    

    const express = require('express'); const app = express(); const PORT = 3000;

    // Route for home page app.get('/', (req, res) => { res.send('Hello World with Express!'); });

    // Route with parameters app.get('/user/:id', (req, res) => { res.send(`User ID: ${req.params.id}`); });

    // Start server app.listen(PORT, () => { console.log(`Express server running at http://localhost:${PORT}`); });

    🧰 Development Tools

    Essential Development Packages:

    BASH
    1
    2
    # Development dependencies
    

    npm install --save-dev nodemon # Auto-restart on changes npm install --save-dev eslint # Code linting npm install --save-dev prettier # Code formatting npm install --save-dev jest # Testing framework npm install --save-dev dotenv # Environment variables

    Debugging Node.js Applications:

    Using Console:

    JAVASCRIPT
    1
    2
    console.log('Regular log');
    

    console.error('Error message'); console.warn('Warning message'); console.table([{name: 'John', age: 30}, {name: 'Jane', age: 25}]);

    Using Chrome DevTools:

    BASH
    1
    2
    3
    # Start Node.js in inspect mode
    

    node --inspect app.js

    # Or with break on first line node --inspect-brk app.js

    Then open chrome://inspect in Chrome browser.

    Using VS Code Debugger:

    1. Create .vscode/launch.json:

    JSON
    1
    2
       {
    

    "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Program", "skipFiles": ["<node_internals>/**"], "program": "${workspaceFolder}/app.js" } ] }

    2. Set breakpoints and press F5 to debug.

    Project Structure Best Practices:

    TEXT
    1
    2
    my-project/
    

    β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ controllers/ # Request handlers β”‚ β”œβ”€β”€ models/ # Data models β”‚ β”œβ”€β”€ routes/ # Route definitions β”‚ β”œβ”€β”€ middleware/ # Custom middleware β”‚ └── utils/ # Helper functions β”œβ”€β”€ public/ # Static files β”œβ”€β”€ tests/ # Test files β”œβ”€β”€ .env # Environment variables (gitignored) β”œβ”€β”€ .gitignore # Git ignore rules β”œβ”€β”€ package.json # Project metadata and dependencies β”œβ”€β”€ README.md # Project documentation └── app.js # Application entry point

    πŸ” Troubleshooting Common Issues

    1. **Node.js/npm Command Not Found**

    BASH
    1
    2
    3
    # Check if Node.js is in PATH
    

    echo $PATH

    # On Windows, you may need to restart after installation # Or manually add to PATH: # C:\Program Files\nodejs\

    2. **Permission Errors (Linux/macOS)**

    BASH
    1
    2
    3
    # Fix global npm permissions
    

    sudo chown -R $USER /usr/local/lib/node_modules sudo chown -R $USER /usr/local/bin sudo chown -R $USER /usr/local/share

    # Or use a node version manager (nvm) instead

    3. **Port Already in Use**

    BASH
    1
    2
    3
    4
    # Find process using port (Linux/macOS)
    

    lsof -i :3000

    # Windows netstat -ano | findstr :3000

    # Kill process kill -9 PID # Linux/macOS taskkill /PID PID /F # Windows

    4. **npm Install Errors**

    BASH
    1
    2
    3
    4
    # Clear npm cache
    

    npm cache clean --force

    # Delete node_modules and package-lock.json rm -rf node_modules package-lock.json

    # Reinstall npm install

    5. **Version Compatibility Issues**

    BASH
    1
    2
    3
    4
    # Check Node.js and npm versions
    

    node --version npm --version

    # Update npm npm install -g npm@latest

    # Use nvm to switch Node.js versions nvm install 18.19.0 nvm use 18.19.0

    6. **Memory Issues**

    BASH
    1
    2
    3
    # Increase memory limit for Node.js
    

    node --max-old-space-size=4096 app.js

    # Set environment variable (permanent) export NODE_OPTIONS=--max-old-space-size=4096

    πŸ“š Additional Resources

    Official Documentation:

  • Node.js Official Documentation
  • npm Documentation
  • Node.js GitHub Repository
  • Learning Platforms:

  • Node.js.dev Learn
  • FreeCodeCamp Node.js Course
  • The Net Ninja Node.js Tutorials
  • Popular Frameworks and Libraries:

  • Express.js: Web application framework
  • Socket.io: Real-time communication
  • Mongoose: MongoDB object modeling
  • Sequelize: SQL ORM for Node.js
  • Jest: Testing framework
  • Webpack: Module bundler
  • Community and Support:

  • Node.js Community
  • Stack Overflow Node.js Questions
  • Node.js Reddit
  • Discord Node.js Community
  • 🎯 Best Practices

    1. Always use version control (git) for your projects 2. Use .gitignore to exclude node_modules and sensitive files 3. Specify exact versions or use semantic versioning in package.json 4. Use environment variables for configuration (never hardcode secrets) 5. Implement proper error handling and logging 6. Write tests for your code 7. Use ESLint and Prettier for code quality 8. Keep dependencies updated (use npm audit and npm outdated) 9. Document your code and write clear README files 10. Use async/await for better asynchronous code readability

    πŸ“¦ Sample Project Checklist

    When starting a new Node.js project:

  • [ ] Initialize with npm init
  • [ ] Set up git repository and .gitignore
  • [ ] Install necessary dependencies
  • [ ] Configure ESLint and Prettier
  • [ ] Create project structure
  • [ ] Set up environment variables
  • [ ] Create entry point (app.js/index.js)
  • [ ] Write initial tests
  • [ ] Configure scripts in package.json
  • [ ] Create README with setup instructions
  • About

    Node.js is a free, open-source, cross-platform JavaScript runtime environment that allows developers to run JavaScript outside of a web browser .


    1 files
    0 folders
    13.46 KB total size
    0 open issues
    0 open pull requests
    0 watchers
    0 forks
    0 stars
    32 views
    Updated Jan 15, 2026
    Languages

    No language data available