NPM — Node.js Technical Interview Questions & Answers
NPM
NPM
- npm is Node’s package manager. npm init -y makes package.json. npm i express installs Express and records it. node_modules is the downloaded code — don’t edit it; don’t commit it if you have a lockfile workflow (commit package-lock.json).
- npx runs a package once. npm run start runs a script from package.json.
- Trap: deleting package-lock to ‘fix’ things. Trap: npm i -g for a project library that should be local.
Technical Interview Tip: npm init -y then npm i express. package.json is the list.
Code Examples for NPM
NPM — working example
const pkg = {
name: "demo",
version: "1.0.0",
scripts: { start: "node index.js" },
dependencies: { express: "^4.19.0" },
};
console.log(pkg.name, Object.keys(pkg.dependencies));NPM — package.json declares scripts and dependencies that npm installs.
How to Explain NPM to an Interviewer
What is package.json?
Project name + scripts + dependencies