Learning path · Level 6 · Tutorial 1

Prepare a Local Project with Node.js and npm

Set up Node.js and npm on your computer, navigate to a project in a terminal, and run a simple JavaScript program through a repeatable package script.

  • Level: Beginner
  • Duration: 20 min
  • 8 steps
Start tutorial Back to the path
Prepare a Local Project with Node.js and npm

What you will go through

  1. Recognize Where Your JavaScript Runs Compare browser and Node.js execution, then identify when browser DOM APIs are required. 2 min
  2. Install Node.js and Verify npm Install a supported Node.js LTS release and verify that Node.js and npm are available from your operating-system terminal. 4 min
  3. Create and Locate Your Project Folder Create a fresh local-project folder, enter it, and verify the current working directory and contents with operating-system-appropriate terminal commands. 3 min
  4. Run a Local JavaScript File Save a local JavaScript file, run it with Node.js from the project folder, and check the terminal result. 2 min
  5. Initialize Project Configuration Create `package.json` in `local-project` and identify initialization as npm project configuration. 2 min
  6. Read and Edit Valid JSON Recognize the JSON syntax required to safely read and edit package.json. 3 min
  7. Run the Program Through a Package Script Define a reusable npm package script, run the local program through it, and identify focused checks for common failures. 2 min
  8. Verify Your Repeatable Local Workflow Update the local program, rerun it through the existing package script, and verify the completed workflow. 3 min

What you will learn

  • Install a compatible Node.js LTS release and verify that node and npm are available in a terminal.
  • Navigate to the intended project folder and confirm its location and contents before running commands.
  • Run a local JavaScript file with Node.js and explain why browser DOM code requires a browser.
  • Initialize an npm project and define a valid package.json script that runs a local program.

Before you start

  • Create and Inspect a Local HTML Page
  • Work with JavaScript Values and Variables

Step 1 of 8

Recognize Where Your JavaScript Runs

Compare browser and Node.js execution, then identify when browser DOM APIs are required.

JavaScript needs a runtime

One language, different runtimes

A runtime is an environment that executes JavaScript. A browser is one runtime: it runs scripts connected to a web page. Node.js is another runtime: it executes JavaScript outside the browser.

The JavaScript language is familiar in both places, but the surrounding capabilities are different. Where a program runs determines which built-in objects it can use.

A diagram compares JavaScript running in a browser with JavaScript running through Node.js in a terminal.

The same language can execute in either runtime, but each runtime supplies different APIs.

Choose the environment by its APIs

The DOM belongs to the browser

Browser code can work with the page's DOM (Document Object Model). For example, document.querySelector() looks for an element in the current browser document.

Standard Node.js execution does not include a browser document, so it does not provide document or browser DOM APIs. A line that needs document.querySelector() therefore requires a browser runtime.

Tip

Node.js and npm have different roles

Node.js is useful for running local development tools and JavaScript programs, but it does not replace the browser that displays a front-end interface.

npm is a separate command-line tool that comes with standard Node.js installations. Later in this tutorial, you will use npm to create project configuration and run a named package script.

Runtime comparison

Compare the capabilities before deciding where code should run.

Choose the runtime based on the APIs your code needs.
CapabilityBrowserStandard Node.js
Display a web pageYesNo
Provide document and DOM APIsYesNo
Run console output codeYesYes
Run local development toolsCan use browser toolsYes

Match code to its runtime

Check your understanding

Match each JavaScript snippet to the environment that can execute it. Focus on whether the snippet only produces console output or needs a browser document.

Match each snippet with its required execution environment.

Tap an item and then its matching pair.

Step 2 of 8

Install Node.js and Verify npm

Install a supported Node.js LTS release and verify that Node.js and npm are available from your operating-system terminal.

Install a compatible Node.js release

Choose a compatible LTS release

Install Node.js from the official Node.js website. Choose the latest supported LTS release by default—not the Current release just because it is newer.

Before selecting a release for a particular development tool, read that tool’s documented Node.js requirements. Choose an LTS release that is both supported now and compatible with the tool. An older release that still says LTS is not automatically suitable.

A standard Node.js installation includes npm. Finish the installation before opening a new terminal to verify both commands.

Install on your operating system

Use the route that matches your operating system. Keep the installer’s standard options that install npm and make the commands available in a terminal.

Use official guidance and complete the installation before version checks.
Operating systemAction
WindowsOn the official Node.js website, select the supported LTS Windows installer for your computer. Run it, keep npm and terminal-command availability selected, then finish the installer.
macOSOn the official Node.js website, select the supported LTS macOS installer for your Mac. Open it, keep npm included, follow the installation steps, and finish.
LinuxIdentify your distribution and version. Follow the official distribution-appropriate Node.js instructions for a supported LTS release, run the documented installation steps, and confirm the installed package provides both node and npm.

Select the right release

A timeline contrasts a highlighted supported LTS release with a separate Current release and an expired older release.

Select a supported LTS release that also meets the documented requirements of the tools you plan to use.

Verify both commands

Use the terminal

On Windows, open Command Prompt. On macOS or Linux, open Terminal.

A terminal shows a prompt when it is ready. The prompt belongs to the terminal, so do not type it. Enter a command, press Enter, then read the output that follows. When the prompt appears again, that command has finished.

After installation, run the two checks below in the operating-system terminal.

Prompt, command, output

A terminal diagram distinguishes the initial prompt, an entered command, output, and the prompt returning afterward.

Read a terminal interaction in this order: prompt, entered command, output, then the returned prompt.

Check Node.js and npm

Command

shell
node --version
npm --version
Expected output
vX.Y.Z
X.Y.Z

Output — placeholders only, not required versions. Your installed values can differ and do not need to match each other.

Tip

Read the result

A successful check prints a version value. Node.js versions commonly begin with v; npm version output is usually numeric. The sample values are placeholders, not targets to match.

Your two successful version values can differ from each other and from this example.

Handle an unavailable command

Recover safely

If either check says that a command is unavailable, unrecognized, or not found, stop before continuing.

  1. Close the terminal and open a new Command Prompt or Terminal window.
  2. Run both checks again.
  3. Recheck the official installation guidance for your operating system and confirm that npm was included.
  4. On a managed work or school computer, ask the administrator or support team for help.

Do not bypass organization restrictions or change advanced system configuration just to make a command work.

Warning

Interpret availability

A version value means that the command is available in this terminal. A command-not-found-style message means that it is not available here yet, even if installation appeared to finish.

Version check results

Compare the two kinds of result.

Version values are placeholders; unavailable-command wording varies by operating system.
Terminal resultMeaningNext action
vX.Y.Z or X.Y.ZCommand is availableContinue
Unavailable or not found messageCommand is not available in this terminalReopen the terminal and recheck installation

Practice: confirm your installation

Report your version checks

On your own computer, run the two version checks from the previous screen in Command Prompt or Terminal. In your answer, include:

  • each command you entered;
  • the actual output line for each command; and
  • whether each result is a successful version result or an unavailable-command result.

Use your computer’s output, not the placeholder values from the lesson. If a command is unavailable, report its message and the recovery step you will take.

Write at least 40 characters (0/40).

Step 3 of 8

Create and Locate Your Project Folder

Create a fresh local-project folder, enter it, and verify the current working directory and contents with operating-system-appropriate terminal commands.

Understand where commands act

Start with the current working directory

A terminal always has a current working directory: the folder where relative file and folder names are resolved. If the current working directory is a parent folder, mkdir local-project creates local-project inside that parent.

Before later project commands, confirm two things: where you are and what the folder contains. A directory listing shows contents; it does not move you to another folder.

How the terminal relates to a folder

A terminal is linked to one highlighted folder in a nested folder tree, representing the current working directory.

The highlighted folder is the terminal's current working directory. Relative names refer to items inside it.

Use the right navigation commands

Find, inspect, and move

Use commands that match your operating system. On Windows, use Command Prompt. On macOS or Linux, use Terminal with a standard shell.

cd local-project enters a child folder. cd .. moves up one level to the parent folder. Check the location and listing again after you move. Listing contents never changes the current working directory.

Terminal command equivalents

Commands for checking and changing the current working directory.

Choose the column that matches your operating system.
PurposeWindows Command PromptmacOS/Linux Terminal
Show current locationcdpwd
List contentsdirls
Enter child foldercd local-projectcd local-project
Move to parent foldercd ..cd ..

Navigate to a Windows path with spaces

Command — Windows Command Prompt absolute path with spaces

shell
cd /d "C:\Users\Alex\Front End"

Navigate to a macOS/Linux path with spaces

Command — macOS/Linux relative path with spaces

shell
cd "Front End"

Tip

Use quotes for spaced paths

Quotes keep a path containing spaces together as one destination. In the Windows example, /d also allows Command Prompt to change drives when necessary. Alex and the absolute path are examples: replace them with your own location.

Make and verify local-project

Create a fresh project folder

Choose a writable parent folder that you can find again. The starting folder in your terminal may differ from the sample home folder below; first navigate to a parent folder where you are allowed to create files.

Inspect that parent folder's location and contents before creating anything. If it already contains a local-project folder that you need to keep, do not delete it. Choose another writable parent folder, inspect it, and then continue.

Windows Command Prompt route

Command — inspect, create, enter, and verify in Windows Command Prompt

shell
cd
dir
mkdir local-project
cd local-project
cd
dir
Expected output
C:\Users\Alex
 Volume in drive C has no label.
 Volume Serial Number is 1234-ABCD

 Directory of C:\Users\Alex

03/14/2026  10:00 AM    <DIR>          .
03/14/2026  10:00 AM    <DIR>          ..
03/14/2026  10:00 AM    <DIR>          Desktop
03/14/2026  10:00 AM    <DIR>          Documents
               0 File(s)              0 bytes
               4 Dir(s)  100,000,000,000 bytes free
C:\Users\Alex\local-project
 Volume in drive C has no label.
 Volume Serial Number is 1234-ABCD

 Directory of C:\Users\Alex\local-project

File Not Found

This is representative sample output from a writable home folder. Replace `Alex` and the path with your own location. Dates, drive details, listings, and free space vary. `mkdir local-project` and `cd local-project` normally produce no output. The first `dir` inspects the parent; the final `dir` confirms that the new project folder is empty.

macOS/Linux Terminal route

Command — inspect, create, enter, and verify in macOS/Linux Terminal

shell
pwd
ls
mkdir local-project
cd local-project
pwd
ls
Expected output
/Users/alex
Desktop
Documents
Downloads
/Users/alex/local-project

This is representative sample output from a writable home folder. Replace `alex` and the path with your own location. The first `ls` inspects the parent folder. A final `ls` produces no file-name output when the newly created `local-project` folder is empty.

Check your navigation plan

Select the verification commands

On macOS or Linux, which two commands verify your current working directory and list its contents?

Complete the quoted Windows path

Complete this Windows Command Prompt command using the example absolute path with spaces from the previous screen.

shell
cd /d ""

Order the folder workflow

Put this workflow in order so that location and contents are verified before a later project command.

  1. Confirm the project location and contents before a later project command.
  2. Confirm the parent location and its contents.
  3. Create local-project.
  4. Enter local-project.
  5. Move to a writable parent folder.

Step 4 of 8

Run a Local JavaScript File

Save a local JavaScript file, run it with Node.js from the project folder, and check the terminal result.

Save the local program

Create and save hello.js

In your own editor, create a file directly inside local-project named hello.js. Paste this complete program and save the file. Keep it beside the other project files, not inside a nested folder.

hello.js

Save this code in hello.js.

javascript
const message = "Hello from Node.js!";
console.log(message);

The file and its folder

A diagram shows hello.js directly inside the local-project folder, connected to a terminal window.

The filename in the terminal command must match the saved file directly inside local-project.

Read the terminal result

Run the saved file

With local-project confirmed as your current working directory, run the saved file. Node.js reads the file from disk, prints its console message, and then finishes. When the terminal prompt returns, the program has ended.

Run hello.js with Node.js

Command

shell
node hello.js
Expected output
Hello from Node.js!

Output — After this line, the terminal returns to its prompt. The prompt itself varies by computer.

Expected terminal result

A terminal runs node hello.js, displays Hello from Node.js!, and then becomes ready for another command.

The console message is program output. The terminal becoming ready again shows that this short program has finished.

Save and check the file

Tip

Save before you run again

Save hello.js before every rerun. Node.js executes the contents stored on disk, not edits that are still unsaved in your editor.

Three quick checks

If the file does not run, pause before changing code. Confirm where the terminal is, then confirm the exact name shown by your editor or directory listing.

Check before rerunning

Use the check that matches what you need to confirm.

Location and filename checks prevent most “file not found” mistakes.
CheckConfirmCommand or action
LocationThe current working directory is local-projectWindows: cd, then dir
LocationThe current working directory is local-projectmacOS/Linux: pwd, then ls
FilenameThe file is named hello.js exactlyInspect the editor tab or directory listing
ExtensionThe name does not end in .js.txtShow file extensions in your file manager

Try the complete workflow

Run the local file

Complete this command. Then run the completed command in your own terminal while local-project is the current working directory.

shell
 hello.js

Report your result

After you run the completed command, state whether the terminal displayed the program message from the earlier example. If it did not run, state which check you tried: current working directory, exact filename, or accidental .txt extension.

Write at least 10 characters (0/10).

Step 5 of 8

Initialize Project Configuration

Create package.json in local-project and identify initialization as npm project configuration.

See what npm adds

A configuration file for this project

hello.js is already a local program in local-project. To make this folder an npm project, npm uses a second file named package.json.

package.json is project configuration: it records settings that npm can use for this specific folder. It belongs directly beside hello.js, not in a separate folder.

Before and after initialization

A comparison of a project folder before it has configuration and after it contains both a JavaScript file and a JSON configuration file.

After initialization, package.json sits beside hello.js inside local-project.

Initialize and inspect

Initialize in the correct folder

First confirm that your current working directory is local-project. Then run this command once. The -y accepts npm’s default answers and creates package.json.

This initializes project configuration only. It does not install Node.js, and it does not execute hello.js.

Create package.json

Command

shell
npm init -y
Expected output
Wrote to C:\Users\Alex\Documents\local-project\package.json:

{
  "name": "local-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

This is a representative npm output. The path, generated fields, and their values can vary with your npm version and settings. The important result is that `package.json` is created in `local-project`.

Check the new file

Open the new package.json in your editor. Near the top, you will normally find project metadata such as a name and version. Generated fields may differ, so do not try to interpret or change every field yet.

Confirm that the file is directly inside local-project, alongside hello.js.

Separate initialization from execution

Check the command’s role

True or false: npm init -y installs Node.js and runs hello.js.

Practice the initialization command

Initialize the project

While your current working directory is local-project, complete the command that creates default npm project configuration. It must not run the JavaScript program or install the Node.js runtime.

shell
npm  -y

Step 6 of 8

Read and Edit Valid JSON

Recognize the JSON syntax required to safely read and edit package.json.

Recognize the JSON Shape

JSON Is Structured Configuration

package.json is configuration data written in JSON, not arbitrary JavaScript. npm must be able to read the entire file, so one misplaced character can stop it from working.

A JSON object starts with { and ends with }. Inside it, each property has a double-quoted key, a colon, and a value. A comma separates one property from the next.

JSON Object Structure

Diagram showing outer braces around JSON properties, with quoted keys and values separated by colons and commas; it also shows that an object can be nested inside another object.

Braces contain an object. Colons connect keys to values, and commas separate properties.

A Valid JSON Example

This small valid JSON object uses the project metadata already introduced.

json
{
  "name": "local-project",
  "version": "1.0.0"
}

Tip

Objects Can Be Nested

A value can also be another object, using braces inside braces: "section": { ... }. The inner object follows the same rules. This nested shape will be useful for configuration later; do not add a new section yet.

Spot Invalid JSON

Punctuation Is Required

Indentation and line breaks make JSON easier to inspect, but punctuation makes it valid. In particular, JSON strings use double quotes—not single quotes. JSON also does not allow comments or a comma after the final property.

Invalid JSON Example

This looks neatly formatted, but it is invalid JSON.

json
{
  "name": 'local-project',
  "version": "1.0.0", // initial release
}

Common JSON Problems

Use this quick check when you edit package.json.

Readable formatting helps, but it cannot correct invalid punctuation.
ProblemWhy it is invalidRequired repair
Single-quoted stringJSON strings require double quotesUse double quotes
No comma between propertiesProperties are not separatedAdd a comma after the earlier value
Comma before `}`There is no following propertyRemove the final comma
`//` commentJSON has no comment syntaxRemove the comment

Practice Required Syntax

Complete the Object

Complete the two missing JSON syntax pieces.

json
{
  : "local-project"
  "version": "1.0.0"
}

Check and Repair JSON

Repair JSON Problems

Match each invalid fragment to the repair or reason that makes the JSON valid.

Tap an item and then its matching pair.

Step 7 of 8

Run the Program Through a Package Script

Define a reusable npm package script, run the local program through it, and identify focused checks for common failures.

From a name to a command

Name a repeatable command

A package script gives a command a reusable name inside package.json. The scripts object maps that name to the command npm should run.

Here, greet maps to node hello.js. When you enter npm run greet from local-project, npm reads that mapping and runs the same local program you previously ran directly.

The script does not change JavaScript behavior and does not start a browser server. hello.js still runs in Node.js and prints its message in the terminal.

Follow the package-script flow

A four-stage diagram shows a terminal command flowing through package.json, then to hello.js executed by Node.js, and finally back to terminal output.

The named command leads npm to the stored command string, which runs hello.js and returns its console output.

Save and run the mapping

Add the scripts object

Open package.json inside local-project and make its contents match this small manifest. The nested scripts object contains the mapping npm will use.

Use valid JSON: keys and string values need double quotes, and properties need commas between them. Save the file before running the command.

Project configuration

package.json

json
{
  "name": "local-project",
  "version": "1.0.0",
  "scripts": {
    "greet": "node hello.js"
  }
}

Run the stored command

Command

shell
npm run greet
Expected output
> local-project@1.0.0 greet
> node hello.js

Hello from Node.js!

Output — example. The first two lines are npm’s script header; the final line is produced by `hello.js`. Minor spacing can vary by npm version.

Practice the configuration

Complete the script entry

Complete the two missing parts of the scripts entry.

json
{
  "name": "local-project",
  "version": "1.0.0",
  "scripts": {
    "": ""
  }
}

Check common outcomes

Verify the workflow

Match each command or symptom to the appropriate action or meaning.

Tap an item and then its matching pair.

Step 8 of 8

Verify Your Repeatable Local Workflow

Update the local program, rerun it through the existing package script, and verify the completed workflow.

Save, then rerun the existing workflow

Update the saved program

You now have a complete local workflow. In your verified local-project folder, keep package.json unchanged and edit hello.js so its saved message changes.

hello.js contains the program. package.json stores the named package script. When you run that script, npm reads the configuration and Node.js executes the saved file.

Before running anything, confirm that your current working directory is local-project and that both files are present. Save the edit before returning to the terminal.

hello.js

Replace the contents of hello.js with this code, then save the file.

javascript
const message = "Hello again from Node.js!";
console.log(message);

Command

Run this from the local-project current working directory after saving hello.js.

bash
npm run greet
Expected output
> local-project@1.0.0 greet
> node hello.js

Hello again from Node.js!

Output: The npm script header can vary slightly by npm version. The important program output is the final line.

One command, saved file, new result

Diagram showing a package configuration directing npm to Node.js, which runs the saved JavaScript file and sends a message to the terminal.

The package script stays the same. Because Node.js reads the saved hello.js file each time, the terminal shows the newly saved message.

Practice: follow the package script

Trace the command flow

Put these stages of one package-script run in order, starting when you enter the command.

  1. Enter the package-script command in the terminal.
  2. npm looks up the named command in package.json.
  3. Node.js executes hello.js.
  4. The terminal prints the message from the saved program.

Practice: complete the invocation

Practice: invoke the script

Complete the terminal command that invokes the existing named package script.

bash
npm run 

Apply the complete workflow

Final application: verify your workflow

Use your own computer to perform the final check in local-project.

In your response, provide all of the following:

  1. Four ordered stages from entering the named command to seeing the program message.
  2. The exact command you entered.
  3. The project location you verified and the actual final program output you saw.
  4. One brief sentence explaining why this Node.js setup cannot directly run browser DOM code that uses document.querySelector().

Write at least 160 characters (0/160).

Finish

Summary

Workflow checklist

You can now repeat a small local Node.js workflow without adding any new tools or packages.

  • Node.js executes the saved JavaScript program outside the browser.
  • npm uses package.json to store and run a repeatable named command.
  • Run project commands only after confirming the current working directory is local-project.
  • hello.js and package.json belong directly inside local-project.
  • Saving hello.js changes what the unchanged greet script executes.
  • Browser DOM code needs a browser document; standard Node.js does not provide it.
  • The next tutorial examines dependencies and lockfiles. No package installation is needed here.

Local workflow ready

Congratulations! You completed: Prepare a Local Project with Node.js and npm

Completed! You updated a saved Node.js program and reran it through the same package script. Your local project is ready for the next tutorial.

Download the App now to have access to + 5000 free courses, exercises, certificates and lots of content without paying anything!

  • 100% free online courses from start to finish

    Thousands of online courses in video, ebooks and audiobooks.

  • More than 60 thousand free exercises

    To test your knowledge during online courses

  • Valid free Digital Certificate with QR Code

    Generated directly from your cell phone's photo gallery and sent to your email

Cursa app on the ebook screen, the video course screen and the course exercises screen, plus the course completion certificate