JavaScript Environment Setup - Guided Notes

CSCI 3403 - Web Programming | Week 9, Class 18

Name: _________________________________ Date: _____________

๐ŸŽฏ Today's Goal: Install Node.js and set up your JavaScript development environment

๐Ÿค” What is Node.js?

Node.js is a JavaScript _______________ environment that allows you to run JavaScript _______________ of your web browser.

Browser JavaScript vs Node.js

Browser JavaScript Node.js
Runs in _______________ Runs on _______________
Access to DOM Access to _______________
Has window object Has _______________ object
Client-side only _______________-side capable
๐Ÿ’ก Remember: Node.js lets JavaScript escape the browser sandbox!

๐Ÿ’ก Why Do We Need Node.js?

List 5 reasons why modern web development requires Node.js:

  1. ๐Ÿ“ฆ _________________________________________
  2. ๐Ÿ› ๏ธ _________________________________________
  3. ๐Ÿงช _________________________________________
  4. ๐Ÿ–ฅ๏ธ _________________________________________
  5. โšก _________________________________________

๐Ÿ”ง Understanding the Tools

NVM vs Node vs NPM - Fill in the descriptions:

Tool Full Name Purpose
NVM ๐Ÿ”„ Node _______________ Manager _________________________________________
Node.js โš™๏ธ JavaScript Runtime _________________________________________
NPM ๐Ÿ“ฆ Node _______________ Manager _________________________________________
โš ๏ธ Don't Confuse: NVM manages _______________ versions. NPM manages _______________. They sound similar but do different things!

๐Ÿ“‹ Why Use NVM Instead of Direct Installation?

List 3 advantages of using NVM:

  1. _________________________________________
  2. _________________________________________
  3. _________________________________________

๐Ÿ” Pre-Installation Check

Check if Node is already installed by running these commands:

$ node _______________
$ which _______________

If you see "command not found", Node is _______________ installed.

If you see a version number like v20.11.0, Node _______________ installed.

๐Ÿ’ป Installation Steps

Choose Your Operating System:

โ˜ Linux     โ˜ macOS     โ˜ Windows (WSL)

Step 1: Install NVM

For Linux:

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

For macOS (with Homebrew):

brew install nvm

โœ… Check: After installation, close and reopen your terminal!

Step 2: Verify NVM Installation

$ nvm --version

You should see a version number like: _______________

Step 3: Install Node.js

$ nvm install _______________

What does LTS stand for? _________________________________________

Step 4: Set Node Version

$ nvm use _______________
$ nvm alias default _______________

Step 5: Verify Installation

Record your versions:

๐Ÿ“ Essential NVM Commands

Complete the command descriptions:

Command What it does
nvm list _________________________________________
nvm list-remote _________________________________________
nvm install 18.19.0 _________________________________________
nvm use 18.19.0 _________________________________________
nvm alias default 20.11.0 _________________________________________

๐Ÿ’ป The Node Console (REPL)

REPL stands for: _______________-_______________-_______________ Loop

REPL Commands:

๐Ÿ“ Practice Exercise:

In the Node REPL, create a function that reverses a string:

function reverseString(str) {
  // Your code here:
  _________________________________________
}

๐Ÿ”ง Common Issues & Solutions

Problem Solution
"nvm: command not found" _________________________________________
"Permission denied" with npm Never use _______________ with npm!
Node version keeps resetting Set a default: nvm alias _______________ node
๐Ÿ’ก Golden Rule: When in doubt, _________________________________________!

๐Ÿ“ฆ Quick NPM Preview

Complete these common NPM commands:

๐Ÿš€ Development vs Deployment

Node.js Development Benefits:

List 3 ways Node.js makes development easier:

  1. _________________________________________
  2. _________________________________________
  3. _________________________________________

Deployment Considerations:

List 3 challenges you might face when deploying Node.js applications:

  1. _________________________________________
  2. _________________________________________
  3. _________________________________________
โš ๏ธ Remember: "It works on my machine!" โ†’ "It works in production!" requires careful planning!

โœ… Best Practices Checklist

Check off as you implement each practice:

๐Ÿ“ Review Questions

  1. What is the main difference between Node.js and browser JavaScript?
    _________________________________________
    _________________________________________
  2. Why should we use NVM instead of installing Node directly?
    _________________________________________
    _________________________________________
  3. What's the difference between NVM and NPM?
    _________________________________________
    _________________________________________
  4. What command exits the Node REPL?
    _______________
  5. What does LTS stand for and why is it important?
    _________________________________________
    _________________________________________

๐Ÿ“ Additional Notes

Use this space for any additional notes, questions, or observations:










๐Ÿ“š Homework

Create a simple Node.js script that reads a file and counts words!

Requirements: