---
title: "Node.js & Express Fundamentals: Building Server Applications"
description: "Master Node.js and Express basics: server creation, routing, middleware, request/response handling, error handling, and REST API development."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/nodejs-express-fundamentals-quiz
---

# Node.js & Express Fundamentals: Building Server Applications

Welcome to the Node.js & Express Fundamentals Quiz! This quiz will test your knowledge of core concepts in building server applications with Node.js and Express. From understanding the basics of Node.js and npm to mastering routing, middleware, and error handling in Express, this quiz is designed to challenge you and help you solidify your understanding of backend development with JavaScript. Whether you're new to Node.js or looking to refresh your knowledge, this quiz is a great way to test your skills. Good luck!

## Questions

### 1. What is Node.js?

- **A JavaScript runtime built on Chrome's V8 engine for server-side execution** ✅
  - Node.js: write backend in JavaScript. Non-blocking I/O, event-driven architecture. Powers many servers.
- A specialized browser extension designed to run compiled JavaScript binary
  - Node.js is server-side runtime.
- A frontend framework used for building complex single-page web applications
  - Node.js is JavaScript with added server capabilities.
- A development environment used solely for local testing and script debugging
  - Node.js used in production at scale (Netflix, Uber).

**Hint:** Think about running JavaScript outside the browser.

### 2. What is npm (Node Package Manager)?

- **The standard package manager used to install and manage project dependencies** ✅
  - npm: package registry (npmjs.com). Manage dependencies in package.json. npm install, npm start, etc.
- A native Node.js plugin used for optimizing the performance of server logic
  - npm is a package manager that comes with Node.js.
- A build tool designed exclusively for bundling frontend assets and libraries
  - Used for both frontend and backend.
- A standalone programming language derived from the original JavaScript core
  - npm is a package manager.

**Hint:** Think about installing dependencies.

### 3. What is package.json?

- **A manifest file declaring metadata, scripts, and required project libraries** ✅
  - package.json: lists dependencies, dev dependencies, scripts. npm uses it to install packages.
- A compiled JavaScript file containing the minified source of the application
  - package.json is metadata file.
- A configuration file used only for managing frontend CSS and HTML templates
  - All Node.js projects use package.json.
- A read-only log file that tracks the history of all package installations
  - Should edit directly for scripts, properties.

**Hint:** Think about project metadata and dependencies.

### 4. What is Express.js?

- **A minimal web framework used for routing, middleware, and request handling** ✅
  - Express: minimal, flexible. Build REST APIs, web servers. Most popular Node.js framework.
- A transport layer protocol used for delivering packages between two servers
  - Express is web framework.
- A unit testing framework designed for checking the logic of backend APIs
  - Express is for servers.
- An optimized version of the Node.js runtime with faster execution speeds
  - Express is a framework on top of Node.js.

**Hint:** Think about a web framework for routing and middleware.

### 5. What is a route in Express?

- **The definition of a URL endpoint and the logic used to generate a response** ✅
  - app.get('/api/users', (req, res) => {}). Routes: GET /users, POST /users, DELETE /users/:id, etc.
- A direct path to a physical file stored within the server-side file system
  - That's file path; route is URL path.
- A navigation method used to redirect users between different browser pages
  - While similar terminology, route in Express is URL endpoint.
- A low-level caching mechanism used to store frequently requested HTML data
  - Route is endpoint mapping.

**Hint:** Think about mapping URLs to handler functions.

### 6. What are HTTP methods in Express routing?

- **Methods corresponding to REST operations such as GET, POST, PUT, and DELETE** ✅
  - app.get(), app.post(), app.put(), app.delete(). PATCH for partial updates.
- Functions that only support fetching data or submitting browser form data
  - Many HTTP methods available.
- Internal Node.js functions that share the same underlying logic and execution
  - Each method has specific purpose.
- Standard browser protocols used to establish a secure socket-based connection
  - All HTTP clients support these methods.

**Hint:** Think about GET, POST, PUT, DELETE.

### 7. What is middleware in Express?

- **Functions having access to the request, response, and the next middleware cycle** ✅
  - Middleware: logging, authentication, parsing. app.use() registers middleware. Call next() to continue.
- Independent software running between the physical client and the web server
  - Middleware in Express is functions.
- A specialized error handling function used for catching unexpected database logs
  - Error middleware exists but middleware general.
- A mandatory configuration required for the execution of every application route
  - Middleware is optional, applied selectively.

**Hint:** Think about functions that process requests before routes.

### 8. What does app.use() do in Express?

- **Registers a specific middleware function to be executed for incoming requests** ✅
  - app.use(middleware) applies to all routes. app.use('/api', middleware) applies to /api routes.
- Includes an external JavaScript library into the main application logic file
  - While it sounds like that, app.use() registers middleware.
- Enables a global configuration setting for the underlying Node.js runtime
  - It applies middleware functions.
- Restricts the application to only handle POST requests from the client-side
  - app.use() applies to all HTTP methods.

**Hint:** Think about registering global middleware.

### 9. What is req (request) object in Express?

- **An object containing request data like headers, URL, body, and parameters** ✅
  - req.body, req.query, req.params, req.headers, req.method. Contains all info sent by client.
- The outgoing object used to send data back to the client from the server
  - That's res; req is the request.
- A direct connection string used to communicate with the project database
  - req is request information.
- A temporary storage object available only for handling GET request types
  - req exists for all HTTP methods.

**Hint:** Think about client-sent data.

### 10. What is res (response) object in Express?

- **An object used to send response data, status codes, and headers to the client** ✅
  - res.status(200).json(), res.send(), res.redirect(). Send response to client.
- The incoming object containing data sent from the client to the server logic
  - That's req; res is the response.
- A persistent storage variable used to keep track of user session information
  - res sends response.
- An object utilized only when a request has been processed with full success
  - res used in all responses (includes error statuses).

**Hint:** Think about sending data back to client.

### 11. What is req.body in Express?

- **A property containing the parsed data sent in the body of the request** ✅
  - req.body contains data sent with POST/PUT. Requires body-parser middleware (included in Express).
- The raw HTML content found within the body tags of the response document
  - That's HTML; req.body is parsed request data.
- A default object that is automatically populated without any middleware
  - Requires middleware; empty if no middleware configured.
- An array used exclusively for handling raw JSON data from an API call
  - Handles JSON, form-encoded, multipart.

**Hint:** Think about accessing POST data.

### 12. What is req.query in Express?

- **An object containing parameters from the URL query string after the ? mark** ✅
  - req.query.q returns "express" for /search?q=express. No middleware needed.
- A specialized function used for executing queries against a connected database
  - That's database; req.query is URL parameters.
- A collection of security headers sent by the browser to authorize the request
  - That's req.headers; query is URL parameters.
- A property that requires custom parsing logic before it can be used in a route
  - Express parses automatically.

**Hint:** Think about URL query parameters.

### 13. What is req.params in Express?

- **An object containing route parameters defined in the path of the URL endpoint** ✅
  - app.get('/users/:id', (req, res) =>{ req.params.id }). Defined in route path.
- A set of optional parameters that follow the question mark symbol in the URL
  - Different: params from path, query from URL.
- A method used to generate a list of all available URL query string attributes
  - That's req.query; params are path parameters.
- A collection of metadata regarding the client browser and operating system
  - That's req.headers.

**Hint:** Think about URL path parameters.

### 14. What is JSON in Express responses?

- **A method that sends a JSON response and sets the correct content-type header** ✅
  - res.json({status: "ok"}). Equivalent to res.type('application/json').send().
- A function that only accepts array-based data to be sent back to the browser
  - res.json() specifically for JSON.
- A variation of res.send() that does not modify the response content-type
  - res.json() sets content-type; res.send() doesn't always.
- A specialized data type used for storing server configuration variables
  - Works with objects, arrays, primitives.

**Hint:** Think about sending data as JSON.

### 15. What is status code in HTTP responses?

- **A numeric code indicating the outcome of a request such as 200, 404, or 500** ✅
  - 2xx: success, 3xx: redirect, 4xx: client error, 5xx: server error. res.status(200).json().
- The content found within the body of the response sent to the web browser
  - Status code is separate from body.
- A default value of 200 that is used for every request handled by the server
  - Different codes for different situations.
- An optional metadata field that can be omitted from the response headers
  - Status codes should always be specified.

**Hint:** Think about 200, 404, 500 codes.

### 16. What is error handling middleware in Express?

- **Middleware defined with 4 parameters used to catch and handle thrown errors** ✅
  - app.use((err, req, res, next) => {}). Must be last middleware. Caught errors passed to it.
- A standard middleware function with 3 parameters used for route validation
  - Error middleware has 4 parameters (includes err).
- A security mechanism that prevents syntax errors from occurring in the code
  - Handles thrown errors, not prevents.
- A development tool used exclusively for logging errors to the local terminal
  - Used in all environments.

**Hint:** Think about handling thrown errors.

### 17. What is next() in Express middleware?

- **A function that passes control to the next middleware function in the stack** ✅
  - next() passes control. If omitted, middleware chain stops. Useful for authentication: pass if auth, skip if not.
- A method used to immediately navigate to the next defined route endpoint
  - next() continues middleware chain.
- A global variable that is always optional within the middleware definition
  - Required to continue chain.
- A function used to stop the execution of all subsequent code in the route
  - next() continues execution.

**Hint:** Think about passing control to next middleware.

### 18. What is CORS in Express?

- **Middleware that allows or restricts cross-origin requests for the server** ✅
  - npm install cors. app.use(cors()). Allows requests from other origins.
- A security protocol used to encrypt data transferred between two origins
  - CORS enables cross-origin; security is in configuration.
- A feature that only allows requests coming from the same original domain
  - CORS specifically for cross-origin.
- A core Node.js feature that is automatically included in the Express library
  - Requires npm package.

**Hint:** Think about cross-origin requests.

### 19. What is body-parser in Express?

- **Middleware used to parse the incoming request body into a usable object** ✅
  - app.use(express.json()). Parses JSON body. express.urlencoded() for forms.
- A security middleware designed to protect against SQL injection attacks
  - body-parser is for parsing, not security.
- An optional feature that is only needed when building large-scale apps
  - Required if handling request bodies.
- A data validation library used to check the length of request body strings
  - Parses all sizes.

**Hint:** Think about parsing request body.

### 20. What is routing in Express, and how is it organized?

- **Mapping URLs to handlers, often organized via the Router for modularity** ✅
  - express.Router() groups related routes. Mount with app.use('/api', router).
- A file-based system where folders automatically determine the URL path
  - Express uses code-based routing.
- A global configuration where every route is defined in a single main file
  - Router enables organized routing.
- A method where URLs are mapped directly to physical files on the server
  - Router allows modular organization.

**Hint:** Think about grouping related routes.

### 21. What is the difference between .send() and .json()?

- **.json() specifies a JSON content-type while .send() is for general data** ✅
  - res.json() is for JSON specifically. res.send() guesses content-type.
- .send() is a legacy method while .json() is the modern replacement function
  - Different purposes.
- .json() is used for objects while .send() is used only for numeric values
  - Both available, .json() more specific.
- Both methods are identical and can be used interchangeably in any route
  - Both work.

**Hint:** Think about content-type headers.

### 22. What is environment variables in Node.js?

- **Variables stored in process.env used for configuration and sensitive keys** ✅
  - dotenv package. process.env.DATABASE_URL. Never commit .env file.
- Global variables that are accessible only within the browser environment
  - Environment variables are system-level.
- Files that must be committed to version control to share project secrets
  - Can come from system, .env file, CI/CD.
- Temporary variables used only during the initial development of the app
  - Used in all environments.

**Hint:** Think about storing secrets and configuration.

### 23. What is the purpose of npm scripts?

- **Commands defined in package.json to automate tasks like starting a server** ✅
  - "scripts": {"start": "node server.js", "test": "jest"}. npm start, npm test.
- Pre-compiled JavaScript files that run before the main application logic
  - Scripts are code shortcuts.
- Internal Node.js functions that cannot be modified by the project author
  - Defined in package.json.
- Build tools used only for minifying and compressing production CSS files
  - Scripts for any purpose: start, test, lint, build.

**Hint:** Think about npm start, npm test.

### 24. What is app.listen() in Express?

- **A method that starts the server and begins listening for incoming requests** ✅
  - app.listen(3000, () => {}). Server listens for requests. Port number specified.
- A function that waits for terminal input before executing the next line
  - listen() starts server, not user input.
- An event listener that only triggers when a specific HTTP error occurs
  - listen() starts HTTP server on port.
- A configuration setting that is only required for local development work
  - Required for running server in all environments.

**Hint:** Think about starting the server.

### 25. What is express.static() middleware?

- **Middleware used to serve static files like images, CSS, and HTML documents** ✅
  - app.use(express.static("public")). Files in public/ accessible via /filename.
- A function that makes application variables immutable and read-only
  - That's a programming concept; static middleware serves files.
- A specialized tool used to cache API responses within the server memory
  - static() serves files; caching is separate.
- A method used to serve only image-based assets from a private directory
  - Serves all file types in directory.

**Hint:** Think about serving HTML, CSS, JavaScript files.

### 26. What is input validation in Express?

- **The process of checking that incoming data matches the expected format** ✅
  - Libraries: joi, express-validator. Check types, lengths, formats. Prevent invalid/malicious data.
- A method for validating HTML form fields directly within the web browser
  - Server-side validation separate from client-side.
- An optional security measure that is not required for production servers
  - Critical for security and data integrity.
- A check that only applies to data sent via POST or PUT request methods
  - Applies to any user input: GET, POST, PUT, DELETE.

**Hint:** Think about validating user-submitted data.

### 27. What is async/await in Node.js?

- **Syntax used to write asynchronous code in a more readable, linear fashion** ✅
  - async function returns Promise. await waits for Promise. Cleaner than .then() chains.
- A method for performing blocking operations that stop the server execution
  - async/await is non-blocking, asynchronous.
- An identical replacement for traditional callback functions and loops
  - Modern alternative to callbacks/promises.
- A feature designed specifically for optimizing SQL database query speeds
  - Works with any Promise-based operation: API calls, file I/O, timers.

**Hint:** Think about handling asynchronous operations cleanly.

### 28. What are Promises in Node.js?

- **Objects representing the eventual success or failure of an async operation** ✅
  - Promise states: pending, fulfilled (resolved), rejected. .then() for success, .catch() for error.
- Internal Node.js events that guarantee a script will complete successfully
  - While conceptually similar, Promises are JavaScript objects.
- A legacy technique used to handle multiple concurrent callback functions
  - Promises improve callback hell.
- Standard data objects used only for handling incoming network requests
  - Promises work for any async operation.

**Hint:** Think about pending, resolved, rejected states.

### 29. What is database connection in Node.js?

- **Establishing a link to a database, often using pools for better efficiency** ✅
  - Libraries: mongoose (MongoDB), sequelize (SQL). Pools reuse connections, avoid overhead.
- A physical cable connection between the web server and the storage server
  - Database connection is software.
- A single global connection that handles all incoming application requests
  - Multiple connections via pooling.
- An automatic process that Node.js performs without any extra configuration
  - Must be configured, managed.

**Hint:** Think about connecting to databases from Express.

### 30. What is URL encoding in Express?

- **Parsing data submitted from HTML forms via application/x-www-form-urlencoded** ✅
  - app.use(express.urlencoded({extended: true})). Parses form data like query strings.
- Encrypting URL parameters to provide extra security for sensitive data
  - URL encoding is about parsing form data.
- A specialized middleware used only for parsing JSON-based request bodies
  - JSON uses express.json(); form data uses urlencoded.
- A default Express feature that does not require any additional middleware
  - Requires middleware.

**Hint:** Think about parsing URL-encoded form data.

### 31. What is session management in Node.js?

- **Storing user-specific data across multiple requests using cookies and stores** ✅
  - Libraries: express-session. Stores session ID in cookie, data on server (memory, Redis, database).
- A security feature designed to prevent users from logging out of the app
  - Sessions enable persistent login.
- A method for storing temporary form data within the browser local storage
  - Sessions store any user data.
- A process where user data is exclusively stored within the client browser
  - Session ID stored in browser; data on server.

**Hint:** Think about storing user state between requests.

### 32. What is REST API in Express?

- **An architectural style utilizing HTTP methods to perform actions on resources** ✅
  - RESTful: Representational State Transfer. Resources (items), methods (GET, POST, PUT, DELETE).
- A real-time data streaming protocol used for live socket-based communication
  - REST is architectural pattern; separate from streaming.
- A database design pattern used only for structuring relational data tables
  - REST is API design pattern.
- A server configuration that requires the use of a NoSQL database system
  - Works with any data source.

**Hint:** Think about architectural style for APIs.

### 33. What is middleware chaining in Express?

- **Executing multiple middleware in a sequence where each calls the next() function** ✅
  - Logging → Auth → Validation → Route handler. Each calls next(). If next() not called, chain stops.
- Running multiple middleware functions at the same time in a parallel process
  - Middleware executes sequentially.
- A deprecated design pattern that is no longer recommended for modern APIs
  - Chaining is common pattern.
- A specific technique used only for handling global application error events
  - Chaining applies to all middleware.

**Hint:** Think about multiple middleware in sequence.

### 34. What is the purpose of console.log in Node.js debugging?

- **Prints information to the terminal for debugging during the development cycle** ✅
  - console.log() for development. Production: winston, pino for structured logs with timestamps, levels.
- Saves debug messages to a persistent log file within the server file system
  - console.log() prints to terminal.
- Automatically identifies and catches syntax errors within the server code
  - console.log() is output; error handling is separate.
- A specialized function used only for printing error messages to the console
  - Can log any information.

**Hint:** Think about logging messages to terminal.

### 35. What is the difference between require() and import?

- **require() follows the CommonJS standard while import uses modern ES modules** ✅
  - const x = require("x"). import x from "x". Node.js now supports both.
- require() is a frontend syntax while import is used only for backend logic
  - Different module systems.
- import is a deprecated method that has been replaced by the require() function
  - import is modern standard.
- Both methods are part of the same system and differ only in their execution speed
  - Both are module load mechanisms.

**Hint:** Think about module import systems.
