🧩 package.json vs package-lock.json — Know the Difference Like a Pro

2 min readApr 29, 2025

If you’re a Node.js developer, you’ve seen package.json and package-lock.json in your projects. But do you understand their roles?

Let’s break it down — precise and tech-first.

📦 What is package.json?

package.json is the manifest of your Node.js project. It describes:

  • What your app is
  • What it does
  • What packages it needs
  • How to run scripts

It’s the first file npm looks at to understand your project.

🔑 Key Sections

{
"name": "my-app",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"nodemon": "^2.0.22"
}
}
  • dependencies: Required to run the app
  • devDependencies: Only for local development
  • scripts: Shortcuts to run commands
  • engines: (Optional) Node and npm versions

🔐 What is package-lock.json?

While package.json defines what your app needs, package-lock.json locks how npm actually installed it.

This file:

  • Pin exact versions of every package and sub-dependency
  • Guarantees consistency across environments
  • Makes installs faster since it doesn’t check the version or updates. It directly installs.
  • Improves security audits (npm audit)

You never write this file manually. It’s generated and updated by npm when you install or update packages.

⚔️ Key Differences

💡 Best Practices

  • Always commit both files to version control.
  • Use npm ci in CI/CD pipelines. It's faster, cleaner, and installs exactly what's in package-lock.json.
  • Don’t manually edit package-lock.json. Let npm handle it.
  • Run npm audit frequently to scan for vulnerable dependencies.

🚀 Final Words

In short:

  • package.json = What your app needs
  • package-lock.json = Exactly what got installed

Understanding both is crucial for stable builds, secure dependencies, and clean collaboration in any Node.js project.

--

--

Visakh Vijayan
Visakh Vijayan

Written by Visakh Vijayan

Techie from Kerala, India. Days are for coding, nights for weaving tales of tech, travel, and finance. Join me in exploring this multifaceted journey

No responses yet