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