Part 2 – Setting Up Your Development Environment

Before diving into Node.js development, you’ll need to set up your environment properly. This guide covers installation, essential tools, and verification steps.

1. Installing Node.js

Windows/Mac

  1. Visit nodejs.org
  2. Download the LTS version (recommended for most users)
  3. Run the installer with default settings

Linux (Ubuntu/Debian)

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

Pro Tip: Avoid installing Node.js from your Linux distro’s default package manager as it often provides outdated versions.

2. Verify Your Installation

Open your terminal/command prompt and run:

node -v
npm -v

You should see version numbers like:

v18.16.0  # Node.js version
9.5.1     # npm version

3. Essential Tools

ToolPurposeInstallation Command
nvmNode Version Manager (switch between versions)curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
nodemonAuto-restart server during developmentnpm install -g nodemon
VS CodeRecommended code editorDownload from official site

4. Configuring Your First Project

Create a new project directory and initialize it:

mkdir my-first-node-app
cd my-first-node-app
npm init -y

This generates a package.json file with default settings.

5. Your First Node.js Script

Create a file named app.js with this content:

console.log("Hello from Node.js!");

function greet(name) {
    console.log(`Welcome ${name}!`);
}

greet("Node Developer");

// Run this with: node app.js

6. Running and Debugging

Basic Execution

node app.js

Outputs:

Hello from Node.js!
Welcome Node Developer!

Debug Mode

node inspect app.js

Use Chrome DevTools by visiting:chrome://inspect

Common Setup Issues

Permission Errors on Linux/Mac

Fix by either:

  1. Using nvm (recommended)
  2. Reinstalling Node.js with correct permissions
  3. Changing npm’s default directory: mkdir ~/.npm-global npm config set prefix '~/.npm-global'

Version Conflicts

Use nvm to manage multiple versions:

nvm install 18.16.0  # Install specific version
nvm use 18.16.0      # Switch to version

Next: Understanding Node Modules & npm →

Cheat Sheet

  • node --version – Check Node.js version
  • npm install -g package – Install global package
  • npm init – Create new project
  • node file.js – Run JavaScript file

Leave a Comment

Your email address will not be published. Required fields are marked *