Interview Q&A / Node.js
Node.js interview questions
The event loop on the server, streams, modules and building APIs with Express.
Prefer rapid revision? Practise Node.js short interview answers →
- What is the difference between dependencies and devDependencies, and why do we need package-lock.json?
dependencies are packages your app needs to run in production; devDependencies are only needed while developing, testing or building. package-lock.json records the exact version of every installed package so every machine and deployment gets the same dependency tree.
BeginnerIn-depth3 min read - What are npm scripts and how do you run them?
Scripts are named shell commands in the scripts field of package.json. Run them with npm run name; start and test also work as npm start and npm test. Local binaries in node_modules/.bin are on the PATH automatically.
BeginnerQuick answer1 min read - What do the caret (^) and tilde (~) mean in package.json versions?
Caret allows updates that do not change the leftmost non-zero version number, so ^1.4.2 accepts 1.x.x at or above 1.4.2. Tilde allows only patch updates, so ~1.4.2 accepts 1.4.x at or above 1.4.2.
BeginnerQuick answer1 min read - What does npm audit do and how should you act on its results?
npm audit checks your dependency tree against a database of known vulnerabilities and reports severity and fixes. Use npm audit fix for safe upgrades, and review breaking or unreachable issues by hand.
BeginnerQuick answer1 min read - What does the main field in package.json do?
main names the entry file that Node loads when someone requires or imports your package by name. If it is missing, Node falls back to index.js. Modern packages may also use the exports field.
BeginnerQuick answer1 min read - What is npx and when would you use it instead of npm install?
npx runs a package's command, using a local copy if present or downloading it temporarily. It is good for one-off tools and project generators, so you avoid installing them globally.
BeginnerQuick answer1 min read - What is semantic versioning and why does it matter for npm packages?
Semantic versioning uses MAJOR.MINOR.PATCH. Increase PATCH for bug fixes, MINOR for backward-compatible features, MAJOR for breaking changes, so users can judge upgrade risk from the number alone.
BeginnerQuick answer1 min read - What is the difference between npm install and npm ci?
npm install can update the lock file and resolves versions from package.json. npm ci deletes node_modules and installs exactly what package-lock.json says, failing if the two disagree, which makes builds repeatable.
BeginnerQuick answer1 min read