OpenViSTAI · Agents · Blockchain · Crypto
Menu

OPENVIST LEARN · FREE LESSONS

npm, packages and project boundaries

Know when a package is needed and avoid running installations merely because an import failed.

Lesson 23 of 25 · About 20 minutes · Beginner · English

By the end of this lesson

Distinguish built-in, local and third-party modules.

Before you start

  • Node.js 24 with a terminal and plain-text editor; the browser-only lesson is labelled separately.
  • Complete lesson 22 or be comfortable with its examples.

Three words to know

npm
A package manager commonly distributed with Node.
Dependency
Software a project needs beyond its own files.
Lockfile
A record used to reproduce a dependency tree.

1. No external dependency for this route

node:fs, node:test and node:assert/strict are built-in modules. ./totals.mjs is your local file. A bare package name usually names an installed dependency. None of the course examples needs an npm install or a package-lock.json to run.

A built-in moduleJAVASCRIPT · Node.js · save as lesson.mjs
import { basename } from "node:path";
console.log(basename("practice.mjs"));
What you should see · example output
practice.mjs

2. Inspect before installing

An import error can mean a misspelled local path, wrong filename or unsupported runtime, not a missing package. For a future third-party dependency, review its publisher, source, licence and maintenance, then install it in that project rather than globally by habit. Packages and lifecycle scripts can execute with your user’s permissions; a project directory is not a security sandbox.

3. Record the environment

A package.json can describe scripts, dependencies and module settings. A lockfile supports reproducible dependency selection. Do not commit node_modules, credentials or private data. For this dependency-free project, recording Node 24, the source and its tests is enough to explain the intended environment. Frameworks, bundlers and publishing a package need later dedicated lessons.

YOUR TURN

A small check before you continue

Do you need npm install fs or npm install node:test? Should a missing ./totals.mjs lead to a registry installation?

Show a suggested answer

No. Those node: APIs are built in, and a missing relative file should be repaired as a local path or file problem. Installing an unrelated package would not restore the intended source.

Sources and scope

Documentation and examples reviewed 2026-10-18. Provider screens, package versions and output wording can differ. Examples show expected outcomes; they are not a claim that OpenViST connected to your server or verified your setup.