learn deep. ship safe.Practice testsFollow ByteMunSubscribe
Node.js · Fresher

Node.js Interview Questions for Freshers

12 Node.js interview questions for freshers and students (0 to 1 year): npm scripts, require and modules, process and paths, the fs module and a basic HTTP server. Each answer explains why the other options are wrong.

CoversEsmFsGlobalsHttpModulesNode.jsNpmPathProcess

By Published Answers checked by Deepak

Take it as a timed test

  • 12 questions
  • 15 min
  • Pass mark 60%
  • Answers shown at the end
Start the timed test

No sign-up. Your answers and scores stay in this browser.

This freshers paper has 12 Node.js questions for freshers and students with roughly 0 to 1 year of experience. It covers npm scripts, require and modules, process and paths, the fs module and a basic HTTP server. Ten questions are on this page with full explanations; the timed test also includes two questions that aren't shown here, so practise for understanding rather than memory.

How should you use this paper?

Answer each practice question before opening its explanation, and say your reasoning out loud the way you would in an interview. Then take the timed test: 15 minutes, a pass mark of 60%, with answers shown at the end. Your report breaks your score down by topic and difficulty, and you can retry only the questions you missed.

Practice questions with answers

Try each one before opening the answer. The explanation covers why the other options are wrong. The timed test also uses 2 questions that aren't shown here, so practise for understanding, not memory.

Q1Choose one answereasy

What is the scripts section of package.json for?

  1. Named commands you run with npm run <name>, such as dev or test
  2. The list of packages to install
  3. JavaScript files that run automatically on install
  4. Browser scripts to include on the page
Show answer and explanation

Answer: A. Named commands you run with npm run <name>, such as dev or test

scripts maps short names to shell commands, so the team runs npm run dev instead of remembering long commands. npm adds node_modules/.bin to the path, so locally installed tools like jest or tsc work without a global install. start and test can be run without run. Dependencies live in dependencies, not here.

Q2Choose one answermedium

In a CommonJS module, what does require('./config') give you?

  1. Whatever ./config assigned to module.exports
  2. A copy of every variable declared in config.js
  3. The file's source code as a string
  4. A Promise that resolves to the module
Show answer and explanation

Answer: A. Whatever ./config assigned to module.exports

require runs the module once, caches it, and returns its module.exports object. Anything not attached to module.exports stays private to the file. A common bug is writing exports = { ... }, which only reassigns the local shortcut and breaks the link; use module.exports = { ... } or add properties with exports.name = ....

Q3True or falsemedium

__dirname is available in ES modules (.mjs files) the same way as in CommonJS.

TrueFalse

Show answer and explanation

Answer: False

False. __dirname, __filename and require are CommonJS module wrappers and don't exist in ES modules. In ESM use import.meta.dirname and import.meta.filename (available in current Node.js releases), or derive them from import.meta.url with fileURLToPath. This trips people up when they switch a project to "type": "module".

Q4Choose one answereasy

You run node app.js hello. What is in process.argv[2]?

  1. "hello"
  2. "app.js"
  3. The path to the node binary
  4. undefined
Show answer and explanation

Answer: A. "hello"

process.argv is an array of strings: index 0 is the path to the Node.js executable, index 1 is the script path, and your own arguments start at index 2. So process.argv[2] is "hello". For real command-line tools, Node's built-in util.parseArgs handles flags and options so you don't parse the array by hand.

Q5What does this code output?easy

What does path.join('/a', 'b', '../c') return?

javascript
const path = require('path');
console.log(path.join('/a', 'b', '../c'));
  1. /a/c
  2. /a/b/../c
  3. /c
  4. a/b/c
Show answer and explanation

Answer: A. /a/c

path.join joins the segments with the platform's separator and then normalises the result, resolving .. and .. So /a/b/../c becomes /a/c. Build file paths with path.join or path.resolve rather than string concatenation, which breaks on Windows and leaves double slashes behind.

Q6Choose one answereasy

Which built-in module do you use to create a basic web server without any framework?

  1. node:http
  2. node:net only
  3. node:fs
  4. node:url
Show answer and explanation

Answer: A. node:http

http.createServer((req, res) => { ... }) gives you a request handler, and server.listen(3000) starts it. Frameworks like Express are built on top of it. net is lower-level raw TCP, fs is for files, and url parses addresses. The node: prefix makes it clear you mean the built-in module, not an npm package with the same name.

Q7Select all that applyeasy

Which of these can you use in a CommonJS Node.js file without importing anything? Select all that apply.

  1. process
  2. Buffer
  3. require
  4. window
  5. document
Show answer and explanation

Answer: A. process + B. Buffer + C. require

Node.js provides process, Buffer, timers, console and, in CommonJS, require and module. window and document are browser APIs for pages and don't exist in Node.js; the global object is globalThis. Code shared between browser and server should check for these before using them.

Q8Choose one answereasy

What is the difference between dependencies and devDependencies?

  1. dependencies are needed to run the app; devDependencies only for building and testing it
  2. devDependencies install faster
  3. There is no difference
  4. dependencies are installed globally
Show answer and explanation

Answer: A. dependencies are needed to run the app; devDependencies only for building and testing it

Runtime packages such as Express go in dependencies. Tools you only need while developing, such as test runners, linters and TypeScript, go in devDependencies. A production install with npm ci --omit=dev skips the dev ones, giving smaller images and fewer packages that could carry vulnerabilities.

Q9Match each item on the lefteasy

Match each fs call to what it does.

  1. fs.promises.readFile
  2. fs.promises.writeFile
  3. fs.existsSync
  4. fs.promises.mkdir with recursive: true
  • Checks if a path exists, blocking briefly
  • Reads a whole file without blocking
  • Creates a folder and any missing parents
  • Creates or replaces a file with new content
Show answer and explanation

Answer: fs.promises.readFile → Reads a whole file without blockingfs.promises.writeFile → Creates or replaces a file with new contentfs.existsSync → Checks if a path exists, blocking brieflyfs.promises.mkdir with recursive: true → Creates a folder and any missing parents

The promise versions don't block the event loop, so prefer them in servers. writeFile overwrites by default; use appendFile to add. existsSync is fine in startup code, but checking then reading creates a race, so it's usually better to just try the operation and handle ENOENT. recursive: true also stops mkdir failing if the folder exists.

Q10Choose one answereasy

What does npx some-tool do?

  1. Runs a package's command, using the local copy or downloading it temporarily
  2. Installs the package globally for every project
  3. Publishes the package to npm
  4. Updates every package in the project
Show answer and explanation

Answer: A. Runs a package's command, using the local copy or downloading it temporarily

npx runs a package binary. If the project has it in node_modules, that copy runs; otherwise npx can fetch it temporarily, which is handy for one-off generators. It avoids global installs, which drift between machines. Be careful running unfamiliar package names with npx: a typo can execute someone else's code.

Answered them all? Take the same questions against the clock and get a topic-by-topic report.

Start the timed test

More Node.js quizzes

All Node.js quizzes →

Senior5+ years

Advanced Node.js Interview Questions

12 Node.js interview questions for senior and lead developers (5+ years): event-loop lag, worker threads versus cluster, memory leaks, graceful shutdown, idempotency, rate limiting and caching. Each answer explains why the other options are wrong.

Test
12 Qs
Time
18 min
Practice
10 Qs