Episode 3 — NodeJS MongoDB Backend Architecture / 3.1 — Starting with NodeJS
3.1 — Exercise Questions: Starting with Node.js
40+ hands-on exercises covering Node.js fundamentals, setup, running scripts, npm, and package.json.
< Package.json Deep Dive | Interview Questions >
How to use this material (instructions)
- Read lessons in order —
README.md, then3.1.athrough3.1.e. - Answer closed-book first — write bullets or a few lines from memory, then compare to the lesson.
- Type code in a real project — create a small Node.js project and test your answers by running scripts.
- Interview prep — pair with
3.1-Interview-Questions.md. - Quick review —
3.1-Quick-Revision.md.
3.1.a — Introduction to Node.js (Q1-Q10)
Q1. In one sentence, what is Node.js? What three things did Ryan Dahl combine to create it?
Q2. Node.js is NOT a programming language, NOT a framework, and NOT a library. Explain what it actually is, using an analogy.
Q3. Name five differences between JavaScript in the browser and JavaScript in Node.js. Use a table format.
Q4. Explain the difference between blocking and non-blocking I/O. Write a 3-line code example for each using fs.readFileSync and fs.readFile.
Q5. Describe the restaurant waiter analogy for the event loop. How does one waiter handle dozens of tables?
Q6. What are the three pillars of Node.js architecture? Name the language each is written in and its role.
Q7. List four use cases where Node.js shines and two where it is NOT ideal. Explain why for each.
Q8. What is libuv? Name three things it handles and explain why it uses a thread pool.
Q9. True or false: "Node.js is single-threaded, so it can only do one thing at a time." Explain your answer.
Q10. Name three companies using Node.js in production and what benefit they reported.
3.1.b — Setting Up Tools and Environment (Q11-Q18)
Q11. Why should you use nvm instead of installing Node.js directly from nodejs.org or via Homebrew?
Q12. Write the nvm commands to: (a) install the latest LTS version, (b) list all installed versions, (c) switch to Node 20, (d) set a default version.
Q13. What is the difference between LTS and Current releases? Which should you use for (a) learning, (b) production, (c) testing new features?
Q14. What is a .nvmrc file? Create one that specifies Node.js 20 and write the command to use it.
Q15. Name five VS Code extensions useful for Node.js development and what each does.
Q16. What is the Node.js REPL? How do you start it? Name three REPL special commands and what they do.
Q17. Write the terminal command to: (a) run a file, (b) evaluate inline code, (c) check syntax without running, (d) start watch mode, (e) load a .env file.
Q18. After installing Node.js, what three commands should you run to verify your setup? What output do you expect?
3.1.c — Running Scripts with Node.js (Q19-Q28)
Q19. Write a complete Node.js script that prints "Namaste Duniya!", the Node version, and the current platform. Run it from the terminal.
Q20. Name six console methods beyond console.log(). For each, describe what it does and whether it writes to stdout or stderr.
Q21. What is the process object? Name five properties or methods on it and what each returns.
Q22. Write a script that reads a --name flag from command-line arguments and prints Hello, <name>!. If no name is provided, exit with code 1 and an error message.
Q23. What is the output of the following code? Explain step by step.
console.log('A');
setTimeout(() => console.log('B'), 0);
process.nextTick(() => console.log('C'));
console.log('D');
Q24. What is the difference between __dirname and process.cwd()? Give a scenario where they return different values.
Q25. Write a script that uses readline/promises to ask the user three questions and then prints a summary.
Q26. What is globalThis and why should you prefer it over global or window?
Q27. Explain why every .js file in Node.js is automatically a module. What does this mean for variable scope?
Q28. Hands-on: Create two files — math.js (exports add and multiply functions) and app.js (imports and uses them). Run app.js and verify the output.
3.1.d — NPM Basics (Q29-Q36)
Q29. What are the three things that "npm" refers to? Describe each in one sentence.
Q30. What happens step-by-step when you run npm install express? List at least five things that occur.
Q31. Explain the difference between these install commands:
npm install expressnpm install nodemon -Dnpm install -g typescriptnpm install express -E
Q32. Why should you NEVER commit node_modules to Git? What should you commit instead?
Q33. What does npx do? Give three practical examples of when you would use it.
Q34. Explain semantic versioning. Given the version ^4.18.2, what versions will npm install? What about ~4.18.2?
Q35. Write the npm commands to: (a) check for outdated packages, (b) update all packages, (c) list top-level dependencies, (d) audit for security vulnerabilities.
Q36. Hands-on: Create a new project from scratch. Initialize it with npm init -y, install chalk as a dependency and nodemon as a dev dependency. Write a script that uses chalk to print colored output. Verify your package.json has both dependency types.
3.1.e — Package.json Deep Dive (Q37-Q45)
Q37. Name ten fields in package.json and describe the purpose of each in one sentence.
Q38. What is the main field used for? What is the difference between main, module, and exports?
Q39. Write npm scripts for: (a) starting the server, (b) development with watch mode, (c) running tests, (d) linting, (e) a prebuild that cleans the dist/ folder. Show the full scripts object.
Q40. What is the difference between dependencies, devDependencies, and peerDependencies? Give two examples of packages for each.
Q41. What does "type": "module" do in package.json? How do you use CommonJS files in an ESM project and vice versa?
Q42. What is the engines field? Write an engines field that requires Node.js 20 or higher. How do you make it a hard error instead of just a warning?
Q43. What problem does package-lock.json solve? What is the difference between npm install and npm ci?
Q44. What does "private": true do? When should you use it?
Q45. Hands-on: Open the package.json of any open-source project (e.g., Express.js on GitHub). Identify and explain every field you find. List any fields not covered in the lesson.
Cross-topic Challenges (Q46-Q50)
Q46. A junior developer clones your repository and says "I ran node app.js but nothing works." Write a troubleshooting checklist of at least six things they should verify.
Q47. Write a complete package.json from memory for a new Express API project. Include: name, version, description, main, type, private, at least 5 scripts with one pre hook, dependencies (express, dotenv, cors), devDependencies (nodemon, jest), and engines.
Q48. Explain the full journey of a JavaScript file from the moment you type node app.js to the moment output appears in the terminal. Mention V8, the event loop, and libuv.
Q49. Code prediction: What is the output of npm run build given this package.json?
{
"scripts": {
"prebuild": "echo Step 1: Cleaning",
"build": "echo Step 2: Building",
"postbuild": "echo Step 3: Done"
}
}
Q50. Hands-on project: Build a command-line quiz app that:
- Reads questions from a JSON file using
fs - Uses
readline/promisesfor user input - Tracks score and prints it at the end
- Has a
package.jsonwithstartandtestscripts - Uses no external packages (built-in modules only)
Answer Hints
| Q | Hint |
|---|---|
| Q2 | JavaScript = language, Node.js = runtime/stage, Express = framework/microphone |
| Q4 | Sync version blocks; async version fires a callback later |
| Q9 | False — JS runs on one thread, but I/O is handled by libuv thread pool + OS kernel |
| Q13 | Even-numbered versions become LTS; odd-numbered are Current only |
| Q23 | Output order: A, D, C, B — nextTick fires before setTimeout(0) |
| Q24 | __dirname = where the file IS; process.cwd() = where the command was RUN from |
| Q27 | Variables in one file do not leak into another; use module.exports to share |
| Q31 | Default = dependencies; -D = devDependencies; -g = global; -E = exact version |
| Q32 | Commit package.json + package-lock.json; node_modules is reproducible from these |
| Q34 | ^4.18.2 allows >=4.18.2 <5.0.0; ~4.18.2 allows >=4.18.2 <4.19.0 |
| Q41 | .js files use ESM; use .cjs extension to force CommonJS in an ESM project |
| Q43 | Lock file records exact versions; npm ci installs strictly from it, npm install may update it |
| Q49 | Step 1: Cleaning, Step 2: Building, Step 3: Done (in that order) |
<- Back to 3.1 — Starting with Node.js (README)