liveBook · Manning

Dependency

As explained in Secrets of the JavaScript Ninja, Third Edition

A software component or package that another component requires in order to build or run.

A software dependency is a package a project uses to add functionality. In JavaScript, Node.js and npm made it easier to share and manage packages; npm records direct dependencies in package.json and downloads their dependency trees into node_modules. section 3.2 section 3.2.1

Adding dependencies can introduce practical risks:

  • An update may bring breaking behavior, and indirect dependencies may require conflicting versions. section 1.4.3
  • A package’s module format may not match the environment, and a third-party package can become a supply-chain attack vector. section 1.4.3
import express from "express";
 
const app = express();
 
app.get("/", (req, res) => {
  res.send("Hello, dependencies!");
});
 
const PORT = 3000;
app.listen(PORT, () => {
  console.log(`Now listening at http://localhost:${PORT}`)
});

This example imports Express, defines a route, and starts a local HTTP server using an installed dependency. section 3.2.1

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Explains npm installation, recursive downloads, and project records; version-range details are deferred.
Examples
Installs Express 5 and imports it to serve a greeting at localhost:3000.
What you can do after
Apply it via npm to install Express, import it, and run a local HTTP server.
How it connects
Connects dependencies with Node.js modules, npm, package.json, package-lock.json, ES modules, and CommonJS.

Also explained in

Compare how 35 books explain dependency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.