Set Up Your Tools: Node.js, npm, Git, VS Code and MongoDB

MERN Stack Full Course: MongoDB, Express, React and Node.js · Foundations · 4 min read · Updated

Your development setup

  1. You write code in an editor such as VS Code.
  2. Node.js runs that code outside the browser, and npm installs packages.
  3. Git records every change, so you can go back and share the project.
  4. MongoDB, installed locally or hosted on Atlas, keeps your data.
  5. The check script prints the version of each tool, so you know the setup is ready.

A good setup saves hours later. This lesson lists exactly what to install, why, and how to check that it works. Nothing here is difficult, but small mistakes, such as an old version of Node.js, cause confusing errors later, so it is worth ten careful minutes now.

What you need

  • Node.js 20 or newer (the current LTS version is the safest choice). It runs your server and also the tools that build the React app. Download it from nodejs.org. It includes npm, the package manager.
  • A code editor. Visual Studio Code is free and works well, but any editor is fine. Useful extensions: ESLint, Prettier and REST Client (we use it in lesson 13).
  • Git, to save versions of your work and to deploy at the end. Install it from git-scm.com.
  • A modern browser with developer tools: Chrome, Edge or Firefox. Press F12 to open them. You will use the Network and Console tabs often.
  • A MongoDB database (lesson 14 shows both options: a free cloud database on Atlas, or MongoDB Community Edition on your computer). You do not need it yet.

Check your installation with a script

Instead of typing three commands and reading three outputs, run the small script from the lab. It asks your computer for the versions of Node.js, npm and Git, and tells you what to fix.

// Lesson 2: check that your computer is ready.   Run:  node examples/02-setup/check-setup.js
import { execSync } from 'node:child_process';

const major = Number(process.versions.node.split('.')[0]);
const tools = [
  { name: 'Node.js', check: () => `v${process.versions.node}`, ok: () => major >= 20, help: 'Install the LTS version from nodejs.org' },
  { name: 'npm', check: () => execSync('npm -v').toString().trim(), ok: () => true, help: 'npm comes with Node.js' },
  { name: 'Git', check: () => execSync('git --version').toString().trim(), ok: () => true, help: 'Install Git from git-scm.com' },
];

let allGood = true;
for (const t of tools) {
  try {
    const version = t.check();
    const good = t.ok();
    if (!good) allGood = false;
    console.log(`${good ? 'OK     ' : 'UPGRADE'} ${t.name}: ${version}${good ? '' : '  -> ' + t.help}`);
  } catch {
    allGood = false;
    console.log(`MISSING ${t.name}  -> ${t.help}`);
  }
}
console.log(allGood ? '\nYou are ready for lesson 3.' : '\nFix the lines above, then run this again.');

Notice what the script does: process.versions.node is information Node.js gives about itself, and execSync('npm -v') runs a command exactly as if you had typed it in the terminal. You will use both ideas again.

Using the terminal

You will type commands in a terminal for most of this course. On Windows use PowerShell or the terminal inside VS Code; on macOS and Linux use Terminal. The few commands you need on day one:

  • cd folder-name moves into a folder, and cd .. moves up one level.
  • ls (macOS and Linux) or dir (Windows) lists the files in the current folder.
  • node file.js runs a JavaScript file.
  • npm install downloads the packages listed in package.json into a node_modules folder.
  • Ctrl + C stops a running program. You will use this every day.

Folder habits that help

Keep the project in a folder whose path has no spaces or special characters, for example C:\projects\mern-job-tracker or ~/projects/mern-job-tracker. Unzip each lesson's solution into a new folder rather than over your own work, so you can compare the two with your editor's “compare files” tool. When you are not sure why your code behaves differently from the lesson, comparing against the zip is the fastest way to find the one line that differs.

Your task

  1. Install Node.js (LTS), Git and VS Code.
  2. Unzip this lesson's solution and run node examples/02-setup/check-setup.js.
  3. Fix every line that says UPGRADE or MISSING, then run it again until it says you are ready.
  4. Run git config --global user.name "Your Name" and git config --global user.email "you@example.com" so your commits carry your name.

How to check it worked

  • Each tool shows OK and the script ends with “You are ready for lesson 3.”
  • node -v prints v20 or higher.

Summary

  • You need Node.js 20+, an editor, Git and a browser. MongoDB comes in lesson 14.
  • The terminal runs your programs; Ctrl + C stops them.
  • Keep secrets and node_modules out of Git.

Download the solution (mern-lesson-02.zip)

Frequently asked questions

Which Node.js version should I install?

The current LTS (long term support) version, as long as it is version 20 or newer. LTS versions get fixes for longer and work with all the libraries in this course.

Can I use Windows for this course?

Yes. Everything works on Windows, macOS and Linux. Use PowerShell or the VS Code terminal on Windows. Commands that differ are noted in the lessons.

Do I need to pay for MongoDB?

No. MongoDB Community Edition is free to run on your own computer, and MongoDB Atlas has a free tier that is enough for this course. Check the Atlas site for the current limits.