Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 1

Node.js 22+ Development Setup on macOS with npm

Recommended resources

¡Hola! Welcome to your first lesson. I'm excited to help you start your journey toward building AI agents to automate and grow your family's event business.

This course is designed to be very hands-on, getting you from the fundamentals to a functional, revenue-generating system. Today, we'll start with the most crucial first step: setting up your "digital workshop." Just as a DJ needs their turntables and mixer set up correctly before a show, a developer needs their programming environment ready before writing any code.

In this lesson, we will set up your macOS computer with Node.js, the runtime environment that will execute the JavaScript code for your AI agents. We will also get familiar with its companion, npm (Node Package Manager), which is like a universal tool for finding and installing all the "parts" or "plugins" you'll need to build your agents. By the end of this hour, you'll have a professional development environment ready for the exciting work ahead.

What is Node.js and Why Do We Need It?

You're already learning JavaScript in your Full Stack course, which is fantastic. You've likely been using it within a web browser. Node.js is a powerful tool that lets us run that same JavaScript code outside of the browser, directly on your computer or a server. This is essential for building backend applications like the AI agents we'll be creating with OpenClaw.


The Best Way to Install Node.js: Using a Version Manager

While you can download Node.js directly from its website, a much better and more professional approach, especially on macOS, is to use a Node Version Manager, or NVM.

Different projects you work on in the future might require different versions of Node.js. NVM allows you to install multiple versions on your machine and switch between them with a simple command. Think of it like a DJ's controller that lets you seamlessly switch between different tracks (Node.js versions) for different parts of your set (your projects). This flexibility prevents future headaches and is standard practice in the industry.

To understand why this is so beneficial, please watch the first few minutes of the following video.

How To Install Node and NVM on Mac / macOS

This video from ProgrammingKnowledge2 explains why using a version manager like NVM is superior to a direct installation.

Watch from the beginning until 02:55. Focus on the explanation of Long-Term Support (LTS) versions and the problem NVM solves by allowing you to switch between Node.js versions easily.


Step 1: Installing NVM and Node.js

Now for the hands-on part. We'll use the terminal to install NVM and then use NVM to install the required version of Node.js (version 22 or newer). Since you're comfortable with the macOS terminal, this should be straightforward.

The following video will walk you through the exact process. I've also provided the commands in a text block below for easy copy-pasting.

How To Install Node and NVM on Mac / macOS

This part of the same video demonstrates the step-by-step installation of NVM and Node.js on a Mac.

Watch from 02:55 to 09:55. Follow the steps to install NVM and then install Node.js. Important: The video installs version 20. For our course, we need version 22 or newer. You can achieve this by using the command nvm install --lts instead of nvm install v20.11.0. The --lts flag will automatically install the latest Long-Term Support version, which is the recommended and most stable choice.

Here are the commands for quick reference. You can execute these one by one in your terminal.

Download Node.js

The official Node.js website provides a concise guide for installing via NVM. Here are the commands you'll need.

Use these commands in your terminal. As mentioned above, use nvm install --lts to get the latest long-term support version, which will satisfy our requirement for Node.js 22+.

After running these commands, you can verify that everything was installed correctly by checking the versions:

# Check Node.js version
node -v

# Check npm version
npm -v

You should see version numbers appear for both, confirming that your development environment is ready!


Step 2: Understanding npm, Your Package Manager

With every installation of Node.js, you also get npm (Node Package Manager). Npm is the heart of the Node.js ecosystem. It's a massive online registry of open-source code packages (tools, libraries, frameworks) and a command-line tool for installing and managing them in your projects.

The key to any npm project is a file called package.json. This file acts as a manifest for your project. It keeps track of:

  • Project metadata (name, version, etc.).
  • The packages your project depends on.
  • Custom scripts for running tasks like starting your application or running tests.

Let's create a simple project to see this in action.

  1. Open your terminal.
  2. Create a new directory for a test project and navigate into it:
    mkdir my-first-node-project
    cd my-first-node-project
    
  3. Initialize a new Node.js project. The -y flag tells npm to use the default settings and create the package.json file automatically.
    npm init -y
    

Now, open this my-first-node-project folder in your code editor (like VS Code) and look at the package.json file. It's a simple JSON object with some basic information.


Installing Your First Package

Now, let's use npm to install a package. A "package" is just a directory with one or more files of code, plus a package.json file. When you install a package, npm downloads it from the registry and places it in a folder called node_modules.

The following video explains this process clearly. While the instructor uses Windows and sets up a project with a tool called Vite, the npm commands and core concepts (package.json, node_modules, dependencies) are exactly the same on your Mac.

npm for absolute beginners

Kevin Powell's video gives an excellent, beginner-friendly tour of npm's core functions.

Watch from 04:04 to 12:18. Ignore the npm create part at the beginning, as we already used npm init. Focus on how npm install works, what the package.json and node_modules are for, and the difference between dependencies and devDependencies.

Test your understanding!

Let's try this yourself. In your my-first-node-project directory, run the following command in the terminal to install a fun package called cowsay that makes an ASCII cow say things.

npm install cowsay

After the command finishes, inspect your package.json file. What new section has been added, and what does it contain? What new folder has appeared in your project directory?

Show answer

You should see a new dependencies section in your package.json file, which now lists cowsay along with its version number. You will also see a new folder named node_modules. This folder contains the code for the cowsay package and any other packages that cowsay itself depends on. This is how npm manages all the code your project needs.


Conclusion

Great work! You've successfully set up the foundational layer of your development environment. This is a critical skill for any modern developer, and you're now ready to build on top of it.

Here are the key takeaways from today's lesson:

  • Node.js is the runtime that allows you to execute JavaScript on your machine, which is essential for building AI agents with OpenClaw.
  • NVM (Node Version Manager) is the best practice for installing and managing different versions of Node.js on macOS, providing flexibility for future projects.
  • npm (Node Package Manager) is your command-line tool for installing and managing third-party code packages.
  • The package.json file is the blueprint for your project, defining its dependencies and other metadata.

In our next lesson, we will tackle a crucial aspect of security and configuration: how to securely load API keys from a local .env file. This will ensure that your secret credentials (like your Anthropic API key) are never accidentally exposed in your code, a vital step before we start interacting with any AI services.