Node.js Junior interview questions and answers

75 questions for a Node.js (Junior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.What is Node.js?
  2. 2.Which JavaScript engine does Node.js use?
  3. 3.What model does Node.js use to handle many connections at once?
  4. 4.Which of these is NOT available in Node.js by default?
  5. 5.What is the name of the global object in Node.js?
  6. 6.How do you run a file app.js with Node.js?
  7. 7.What is the Node.js REPL?
  8. 8.What does node --watch app.js do?
  9. 9.Which Node.js release lines are recommended for production?
  10. 10.What is libuv in Node.js?
  11. 11.Which two module systems does Node.js support?
  12. 12.How do you export a function in CommonJS?
  13. 13.Why does exports = { add } not export anything in CommonJS?
  14. 14.How does Node.js decide that a .js file is an ES module?
  15. 15.What is required in an ES module import of a local file that is optional in require()?
  16. 16.Which variables are not available in an ES module but exist in CommonJS?
  17. 17.What does require() do if the same module is required twice?
  18. 18.What is the recommended way to import a built-in module?
  19. 19.What does import() (with parentheses) do?
  20. 20.Where does require("lodash") look for the package?
  21. 21.What is package.json?
  22. 22.What is the difference between dependencies and devDependencies?
  23. 23.What is package-lock.json for?
  24. 24.What does the version range ^1.4.2 allow?
  25. 25.In semantic versioning MAJOR.MINOR.PATCH, when should MAJOR increase?
  26. 26.How is npm ci different from npm install?
  27. 27.How do you run a script defined in package.json like this?
  28. 28.What does npx do?
  29. 29.Should node_modules be committed to git?
  30. 30.What does npm audit do?
  31. 31.What does 'non-blocking I/O' mean in Node.js?
  32. 32.What is an 'error-first callback'?
  33. 33.What is 'callback hell'?
  34. 34.What is the order of the output?
  35. 35.How do you get a promise-based version of the fs API?
  36. 36.What does util.promisify do?
  37. 37.Can you use await at the top level of a file (outside any function) in Node.js?
  38. 38.How do you run two independent async requests in parallel and wait for both?
  39. 39.What happens if a promise rejects and nothing handles the rejection?
  40. 40.What is an EventEmitter?
  41. 41.What will this code print?
  42. 42.Is emitter.emit() synchronous or asynchronous?
  43. 43.Why should you avoid fs.readFileSync inside an HTTP request handler?
  44. 44.What does path.join("/users", "anna", "../docs", "file.txt") return on Linux?
  45. 45.How is path.resolve() different from path.join()?
  46. 46.Why use the path module instead of joining paths with + "/" +?
  47. 47.How do you read an environment variable PORT?
  48. 48.How can Node.js load variables from a .env file without extra packages?
  49. 49.What does process.argv contain?
  50. 50.What does process.exit(1) mean?
  51. 51.What is the difference between process.cwd() and __dirname?
  52. 52.Which module gives information about the operating system, such as CPU count and free memory?
  53. 53.How do you append a line to a file using promises?
  54. 54.How do you check whether a file exists before reading it?
  55. 55.What does the error code ENOENT mean?
  56. 56.How do you create a folder together with any missing parent folders?
  57. 57.What does this code do?
  58. 58.What happens if a request handler never calls res.end()?
  59. 59.Can you use fetch() in Node.js without installing a package?
  60. 60.What is Express?
  61. 61.What is middleware in Express?
  62. 62.How do you read the JSON body of a POST request in Express?
  63. 63.How do you read 42 from the URL /users/42 in Express?
  64. 64.Which HTTP status code should an API return when a resource is created?
  65. 65.What is the difference between status codes 401 and 403?
  66. 66.What is CORS, and where is it enforced?
  67. 67.How do you catch an error from an awaited promise?
  68. 68.What happens when an error is thrown and nothing catches it?
  69. 69.How do you debug a Node.js app in Chrome DevTools or VS Code?
  70. 70.What is JSON.parse likely to do with invalid input?
  71. 71.What is the built-in way to write tests in Node.js?
  72. 72.Can recent Node.js versions run a .ts file directly?
  73. 73.Which statement about console.log in a high-traffic server is true?
  74. 74.What does setting NODE_ENV=production usually do?
  75. 75.Why should secrets like database passwords not be hard-coded in the source?