Node.js — Server-side JavaScript Study Material

Installation & version managers

Overview

Node.js is a free, open-source, cross-platform JavaScript runtime environment that allows developers to execute JavaScript code outside of a web browser. It is primarily used to build fast, scalable, and high-performance server-side network applications


1. Node.js Installation


Installing Node.js is the first step for any developer. While you can download a direct installer from the official website, professional setups often prefer version managers to avoid permission issues and allow for flexibility.


  • LTS vs. Current:


    • LTS (Long Term Support): Recommended for most users. It’s stable and receives security updates for years.

    • Current: Includes the latest features but may be less stable.

  • The Ecosystem: Installing Node.js automatically installs npm (Node Package Manager), which is essential for managing external libraries.



2. Node Version Managers (NVM)


In a professional setting, you might work on one project that requires Node 16 and another that requires Node 20. Version managers allow you to switch between them instantly.


Popular Tools

  • nvm (Node Version Manager): The industry standard for macOS and Linux.

  • nvm-windows: The most popular choice for Windows users.

  • fnm (Fast Node Manager): A newer, extremely fast alternative built in Rust.


Why use a Version Manager?

  1. Project Isolation: Prevents "it works on my machine" bugs by ensuring every developer uses the same version.

  2. No Sudo Required: Avoids using sudo for global installs on Linux/macOS, which is a major security plus.


  3. Easy Upgrades: Test your app on a new Node version with a single command before committing to an upgrade.


3. Key Commands (Cheat Sheet)


Below are the "must-know" commands:


 Command Description
 node -v Checks the currently installed Node version.
 nvm install [version]   Downloads and installs a specific version.
 nvm use [version] Switches the active Node version for the current terminal.
 nvm list Shows all Node versions currently installed on the machine.
Node.js — Server-side JavaScript Study Material | Careeroza