curriculum/challenges/english/blocks/review-npm/69a99035edde234d544d003f.md
Definition: npm is an online registry for open-source software, functioning like an "app store" for code.
Official Meaning: npm does not officially stand for "Node Package Manager"; it is a recursive backronymic abbreviation for "npm is not an acronym".
Three Related Parts:
Alternatives: While npm is most widely used, popular alternatives include Yarn, PNPM, and Bun.
Purpose: A configuration file that stores metadata, dependencies, and scripts for a Node.js project.
Key Fields:
name and version: Identify the project.main: Specifies the entry point file, often index.js.license: Defines legal terms (default is ISC).dependencies: Packages required to run the app in production.devDependencies: Tools only needed during development, such as testing frameworks.Creation:
npm init: Starts an interactive setup process.npm init -y: Installs a package.json with default values instantly.Format: MAJOR.MINOR.PATCH.
Rules:
Range Symbols:
^ (Caret): Allows minor and patch updates (e.g., ^1.2.3 allows 1.x.x).~ (Tilde): Allows only patch updates (e.g., ~1.2.3 allows 1.2.x).* (Asterisk): Matches any version; used primarily for testing.Installation:
npm install <name>: Adds a production dependency.npm install <name> -D: Adds a development dependency.npm install <name>@<version>: Installs a specific version.Node Modules & Locks:
node_modules/: Contains the actual code for installed packages.package-lock.json: Locks the exact versions of all dependencies and "child dependencies" to ensure consistency across environments.Removal: npm uninstall <name> removes the package and updates package.json.
Maintenance:
npm outdated: Identifies which packages have newer versions available.npm update: Updates packages within the allowed SemVer range.scripts section of package.json to automate tasks.npm run <script_name>.start, test, stop, and restart (e.g., npm start).&&: Runs the second command only if the first succeeds.;: Runs commands one after another regardless of success.& operator to run processes in the background.-- separator (e.g., npm start -- 8000).npmjs.com.npm login.name and valid version are in package.json.README.md and .npmignore (to exclude sensitive files).npm publish (or npm publish --access public for scoped packages).@username/package-name.const module = require('./path').module.exports = { functionName }..cjs files or .js files when no type is specified in package.json.Standardized Format: Modern JavaScript standard; loads asynchronously for efficiency.
Syntax:
export { name } or export default function.import { name } from './path.mjs'..mjs files or .js files when package.json contains "type": "module".Review the npm topics and concepts.