npm: fundamentals, package manager for React Native and Node.js

Author: IT Sectr Published: 2026-02-13 Reading time: 10 min

npm (Node Package Manager) is the standard package manager for the Node.js platform, included in the Node.js installation. npm manages dependencies of JavaScript and TypeScript projects: installs libraries into node_modules, updates package versions, resolves version conflicts. package.json is the central configuration file with metadata and a list of dependencies. The npm Registry is the largest package registry. Learn more at npm Registry.

Key Takeaways

  • npm — the standard Node.js package manager, included with Node.js since version 0.6.3
  • package.json — the project configuration file with dependencies, scripts, and metadata
  • npm install — the basic command to install dependencies from package.json into the node_modules folder
  • package-lock.json — the exact version lock file for reproducible installs across all environments
  • npm ci — the CI/CD command that installs packages strictly from the lock file without updating it

What is npm — the Node.js package manager?

npm was created in 2010 by Isaac Schlueter as a solution for managing Node.js dependencies. Since 2014 npm has been managed by npm, Inc., acquired by Microsoft/GitHub in 2020. The tool consists of two parts: the CLI (command line) for installing and managing packages, and the Registry — the central repository of all published modules at registry.npmjs.org.

The npm Registry is the largest package registry: over 2 million packages and more than 10 billion downloads monthly. Each package has a SemVer version, description, dependencies, license, and authorship. Publishing your own package is done via npm publish. npm supports scoped packages for organizations (@scope/package), private registries, and built-in security auditing.

Node.js version 18+ includes npm 9+ with improved performance, workspaces for monorepos, and a reworked peer dependencies mechanism. The npm ecosystem covers server-side JavaScript, frontend (React, Vue, Angular), mobile development (React Native), build tools (Webpack, Vite), and CLI utilities. npm is the primary distribution channel for JavaScript libraries.

Key npm Features

npm install — the main command that reads package.json and package-lock.json to install all dependencies into node_modules. On first run, npm computes the dependency graph, resolves version conflicts, and generates package-lock.json. The npm install <package> command installs a specific package; the --save-dev flag adds it to devDependencies, --global installs globally.

npx — a package runner included in npm since version 5.2. npx allows running CLI utilities without global installation: npx react-native init or npx create-react-app my-app. npx downloads the package to a temporary cache, runs it, and cleans up after completion. npx is also useful for running specific tool versions.

npm audit scans the dependency tree for known vulnerabilities from the npm database. The command outputs a report with severity levels (critical, high, moderate) and recommends npm audit fix to automatically update vulnerable packages. npm cache stores downloaded packages locally. npm cache clean --force clears the cache when installation issues arise. npm outdated shows outdated packages.

bash
# Basic npm commands
$ npm install
$ npm install react-native-webview --save
$ npm install typescript --save-dev
# Running without global installation
$ npx react-native init MyApp
# Security audit
$ npm audit --fix

package.json Structure and Dependency Management

package.json is a JSON file in the project root that describes its metadata, dependencies, and configuration. Required fields: name (unique package name) and version (SemVer version, e.g. 1.0.0). The file is created with npm init -y for quick initialization or manually.

Semantic Versioning (SemVer) is a versioning standard in MAJOR.MINOR.PATCH format. The major version changes with incompatible API changes, the minor version changes when adding functionality (backward compatible), and the patch version changes for bug fixes. The ^ symbol before a version allows minor and patch updates, while ~ allows only patch updates.

json
{
  "name": "my-app",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios"
  },
  "dependencies": {
    "react": "^18.3.0",
    "react-native": "^0.76.0"
  },
  "devDependencies": {
    "typescript": "^5.5.0",
    "@types/react": "^18.3.0"
  }
}
FieldPurposeExample Value
scriptsRun commands for npm run"start": "node index.js"
dependenciesProduction dependencies of the application"react": "^18.3.0"
devDependenciesDevelopment and testing tools"jest": "^29.7.0"
peerDependenciesHost dependencies for libraries"react": ">=17.0.0"
enginesNode.js version requirements{"node": ">=18.0.0"}

npm in React Native Development

React Native projects actively use npm for dependency management. The standard set includes react, react-native, navigation libraries (React Navigation), HTTP libraries (axios), state management (Redux, Zustand), and UI components. npm allows installing thousands of compatible packages from the registry.

npx pod-install — a required command after installing native modules in React Native for iOS. npm automatically generates a Podfile.lock based on package-lock.json. In Expo projects, expo install is used instead of npm install, as it selects versions compatible with the current Expo SDK version.

Version conflicts are a common issue in React Native: react-native-reanimated, react-native-gesture-handler, and react-native-safe-area-context require aligned versions. The solution is to update all packages to the latest compatible versions or use --legacy-peer-deps. package-lock.json is critical for native modules compiled via CocoaPods and Gradle.

npm vs Alternative Package Managers

npm is the standard package manager included with Node.js. The main alternatives: yarn (created by Facebook in 2016) and pnpm (fast, with hard links). Since npm 5, the difference in speed and functionality between npm and yarn is minimal. npm 7+ added workspaces, making it competitive for monorepos.

Featurenpmyarnpnpm
Year Created201020162017
Lock Filepackage-lock.jsonyarn.lockpnpm-lock.yaml
InstallationSequential (npm 5+)ParallelParallel
Disk SpaceStandardStandardMinimal (links)
WorkspacesYes (npm 7+)YesYes
Plug'n'PlayNoYesNo

According to State of JS 2025: 62% of developers use npm, 35% use yarn (mostly older projects and PnP enthusiasts), and 3% use pnpm. For React Native projects, both tools are equally viable, but npm is more common in projects using Expo SDK 50+ and new React Native initializations.

yarn retains its advantage in extremely large monorepos (100+ packages) thanks to its more mature workspaces implementation and Plug'n'Play. pnpm wins in disk space savings through hard links to a global store. The choice of manager depends on team preferences and infrastructure.

Frequently Asked Questions

What is the difference between npm install and npm ci?

npm install updates package-lock.json and may install new minor versions within the semantic range. npm ci (Clean Install) removes node_modules and installs packages strictly from package-lock.json without updating it. npm ci is faster, used in CI/CD, and guarantees an identical environment on all machines. If package-lock.json is missing, npm ci throws an error.

How to fix peer dependency conflicts in npm?

Since npm 7, peer dependency conflicts cause build errors. Solutions: update all packages to compatible versions via npm update, use the --legacy-peer-deps flag for npm 6 mode, or add an overrides section in package.json to force a specific package version. The best option is to update dependencies to compatible versions.

What is npm audit and why is it needed?

npm audit scans the dependency tree for known vulnerabilities from the npm Security Advisory database. The command outputs a report with severity levels (critical, high, moderate, low) and recommends npm audit fix to automatically update vulnerable packages to safe versions. Regularly running npm audit is a basic security practice for JavaScript projects.

How do npm workspaces simplify monorepos?

npm workspaces allow managing multiple packages in a single repository. Add the "workspaces": ["packages/*"] field to the root package.json. Benefits: single install of all dependencies into a shared node_modules, automatic symlinks between local packages, running scripts for all packages from the root, and eliminating version duplication.

Why commit package-lock.json to the repository?

package-lock.json locks the exact versions of all dependencies and their transitive packages. Without it, different developers and CI servers may get different library versions within the semantic range, leading to "it works on my machine" errors. Committing the lock file guarantees reproducible builds and identical behavior across all environments.

Summary

  • npm — the standard Node.js package manager, included with Node.js since version 0.6.3
  • package.json — the project configuration file with dependencies, scripts, and metadata
  • npm install — installs dependencies, npm ci — installs strictly from package-lock.json for CI/CD
  • package-lock.json — exact version lock, required for reproducible builds
  • npm Registry — the largest package registry with over 2 million modules
  • npm audit — dependency security check with automatic vulnerability fixing
  • npm workspaces — monorepo management mechanism with shared node_modules

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also