0
0
Node.jsframework~20 mins

package-lock.json and deterministic installs in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Lock File Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the main purpose of package-lock.json?
Why does Node.js create a package-lock.json file when you install packages?
ATo store user credentials for npm registry access
BTo lock the exact versions of installed packages for consistent installs across environments
CTo list all outdated packages that need updating
DTo define scripts for running tests and builds
Attempts:
2 left
💡 Hint
Think about how to make sure everyone gets the same package versions.
component_behavior
intermediate
1:30remaining
What happens if package-lock.json is deleted before npm install?
If you delete package-lock.json and then run npm install, what is the most likely outcome?
Anpm installs only devDependencies and skips regular dependencies
Bnpm refuses to install any packages without package-lock.json
Cnpm installs packages exactly as before without any changes
Dnpm installs the latest compatible versions based on package.json, possibly different from before
Attempts:
2 left
💡 Hint
Without the lock file, npm has no record of exact versions.
📝 Syntax
advanced
2:00remaining
Identify the error in this package-lock.json snippet
Look at this snippet from a package-lock.json file. What is wrong with it?
Node.js
{
  "name": "my-app",
  "version": "1.0.0",
  "lockfileVersion": 2,
  "dependencies": {
    "express": {
      "version": "4.17.1",
      "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz",
      "integrity": "sha512-...",
      "requires": {
        "accepts": "~1.3.7"
      }
    }
  },
  "devDependencies": {}
}
AMissing comma after the dependencies object before devDependencies
BThe version field should be a number, not a string
ClockfileVersion must be 1, not 2
DThe integrity field should be a boolean, not a string
Attempts:
2 left
💡 Hint
Check JSON syntax carefully between objects.
state_output
advanced
2:00remaining
What version of lodash will be installed?
Given this package.json and package-lock.json snippet, what version of lodash will npm install?
Node.js
{
  "dependencies": {
    "lodash": "^4.17.15"
  }
}

// package-lock.json snippet:
{
  "name": "my-app",
  "lockfileVersion": 2,
  "dependencies": {
    "lodash": {
      "version": "4.17.21",
      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
      "integrity": "sha512-..."
    }
  }
}
A4.17.21 (the version locked in package-lock.json)
B4.17.15 (the minimum version specified in package.json)
CThe latest lodash version available on npm
DInstallation will fail due to version conflict
Attempts:
2 left
💡 Hint
npm prefers the lock file version for installs.
🔧 Debug
expert
2:30remaining
Why does npm install produce different results on two machines?
Two developers run npm install on the same project with the same package.json but different package-lock.json files. What is the most likely cause of different installed package versions?
Anpm caches are always cleared on install, so versions differ randomly
Bpackage.json overrides package-lock.json during install
CThe package-lock.json files differ, causing npm to install different exact versions
Dnpm install ignores package-lock.json if node_modules exists
Attempts:
2 left
💡 Hint
Check if the lock files are identical on both machines.