Node.js Interview Questions: Beginner to Expert
Practice 60 popular Node.js interview questions covering fundamentals, asynchronous programming, Express, databases, security, performance, concurrency, scalability, and production architecture.
What is Node.js?
Node.js is an open-source, cross-platform JavaScript runtime environment that allows JavaScript to run outside the browser. It is built on Google's V8 JavaScript engine and is commonly used for backend services, APIs, command-line tools, real-time applications, and automation. Node.js uses an event-driven architecture and non-blocking I/O, making it well suited for applications that handle many concurrent I/O operations.
- Node.js is a runtime, not a programming language.
- It uses the V8 JavaScript engine.
- It is commonly used for server-side JavaScript.
- Its event-driven model is suitable for I/O-heavy applications.
What is Node.js?
Is Node.js a programming language?
No. Node.js is not a programming language. JavaScript is the programming language, while Node.js is a runtime environment that provides APIs and infrastructure for executing JavaScript outside a browser. Node.js provides capabilities such as file-system access, networking, streams, processes, and HTTP servers.
- JavaScript is the language.
- Node.js is the runtime.
- Node.js adds server-side and system-level APIs to JavaScript.
Which statement correctly describes Node.js?
Why is Node.js popular for backend development?
Node.js is popular because it allows developers to use JavaScript across the frontend and backend, has a large npm ecosystem, provides efficient non-blocking I/O, and works well for APIs, real-time applications, microservices, and other I/O-heavy systems. Its asynchronous programming model can efficiently handle many concurrent requests without creating one operating-system thread per request.
- JavaScript can be used across the stack.
- npm provides a large package ecosystem.
- Non-blocking I/O supports high concurrency.
- Node.js is particularly strong for I/O-heavy workloads.
Which characteristic makes Node.js particularly useful for I/O-heavy backend applications?
What JavaScript engine does Node.js use?
Node.js uses the V8 JavaScript engine, originally developed by Google for Chrome. V8 parses and executes JavaScript and uses techniques such as just-in-time compilation to optimize JavaScript execution. Node.js adds its own runtime APIs around the JavaScript engine.
- Node.js uses V8.
- V8 executes JavaScript.
- Node.js adds runtime APIs around V8.
Which JavaScript engine powers Node.js?
What is npm?
npm originally stood for Node Package Manager and is the standard package manager commonly used with Node.js. It is used to install, update, remove, and manage project dependencies and to run scripts defined in package.json. npm also provides access to a large public package registry.
- npm manages dependencies.
- npm can execute package.json scripts.
- npm provides access to a large package registry.
What is npm primarily used for?
What is package.json?
package.json is the manifest file for a Node.js project. It commonly contains the project name, version, scripts, dependencies, development dependencies, module configuration, metadata, and other project settings. It allows npm and other tooling to understand how the project should be installed and executed.
- package.json describes a Node.js project.
- Dependencies and scripts are commonly defined there.
- It is a central configuration file for npm projects.
What is the main purpose of package.json?
What is package-lock.json?
package-lock.json records the resolved dependency tree and exact package versions installed for a project. It helps ensure reproducible installations across machines and environments. It can contain information about transitive dependencies, package versions, integrity information, and resolved package locations.
- package.json declares dependencies.
- package-lock.json records resolved dependency versions.
- Lock files improve reproducibility.
What is the primary purpose of package-lock.json?
What is the difference between dependencies and devDependencies?
dependencies are packages required by the application at runtime. devDependencies are generally packages needed during development, testing, linting, formatting, or building but not necessarily required to run the production application. For example, Express may be a dependency, while a testing framework or ESLint may be a devDependency.
- dependencies are runtime dependencies.
- devDependencies are generally development/build/test dependencies.
- Correct classification helps production installations remain lean.
Where would a package required by the production application normally be placed?
What is CommonJS?
CommonJS is a module system historically used extensively in Node.js. It uses require() to import modules and module.exports or exports to expose values. CommonJS modules are typically loaded synchronously and have their own module scope.
- CommonJS is a Node.js module system.
- require() imports modules.
- module.exports exports values.
Which syntax is associated with CommonJS modules?
What are ES Modules?
ES Modules, commonly called ESM, are the standardized JavaScript module system using import and export syntax. Modern Node.js supports ESM alongside CommonJS. ESM can be enabled through configuration such as package.json type: module or appropriate file extensions such as .mjs.
- ESM uses import/export.
- Node.js supports both ESM and CommonJS.
- Module-system configuration should be consistent within a project.
Which syntax is used by ES Modules?