Top Interview NodeJs Questions For Capgemini
Top Basic Node.js Interview Questions and Answers for Capgemini
Introduction
Are you preparing for a Node.js interview at Capgemini? Node.js is an open-source, cross-platform JavaScript runtime environment widely used for building fast, scalable, and real-time backend applications. Capgemini frequently evaluates candidates on asynchronous programming, event-driven architecture, API development, Express.js, and performance optimization in Node.js.
This blog provides a comprehensive list of basic Node.js interview questions to help freshers and experienced developers succeed in their Capgemini technical interview.
✔ Covers essential Node.js concepts
✔ SEO-optimized for better ranking
✔ Includes practical examples
✔ Suitable for freshers and experienced developers
📌 Bookmark this page and revise these questions before your Capgemini Node.js interview! 🚀
Top Basic Node.js Interview Questions and Answers
1. What is Node.js?
Answer: Node.js is an open-source, event-driven, non-blocking JavaScript runtime environment that runs on Chrome’s V8 engine. It is used to build scalable and high-performance backend applications.
2. What are the key features of Node.js?
Answer:
- Asynchronous and Event-driven – Uses a non-blocking I/O model
- Single-threaded but highly scalable – Handles multiple requests efficiently
- Built-in Package Manager (NPM) – Manages reusable modules
- Cross-platform – Works on Windows, macOS, and Linux
- Fast Execution – Runs on Google’s V8 engine
3. What is the difference between JavaScript and Node.js?
Answer:
Feature | JavaScript | Node.js |
---|---|---|
Execution | Runs in browsers | Runs on the server |
Usage | Frontend scripting | Backend development |
Libraries | DOM, BOM | Express, MongoDB, File System |
4. What is an event-driven architecture in Node.js?
Answer: Node.js uses an event-driven architecture, where the EventEmitter module listens for and handles events asynchronously.
Example:
const EventEmitter = require("events");
const event = new EventEmitter();
event.on("message", () => {
console.log("Event triggered!");
});
event.emit("message"); // Output: Event triggered!
5. What is the difference between synchronous and asynchronous programming in Node.js?
Answer:
Type | Synchronous | Asynchronous |
---|---|---|
Execution | Blocks further execution | Non-blocking execution |
Example | fs.readFileSync() | fs.readFile() |
Performance | Slower | Faster and scalable |
6. What is the purpose of NPM (Node Package Manager)?
Answer: NPM is used to install, update, and manage Node.js packages and dependencies.
Example to install a package:
npm install express
7. What are Node.js modules?
Answer: Modules in Node.js are reusable blocks of code that can be exported and imported.
Example:
// myModule.js
module.exports = function () {
console.log("Hello from Module!");
};
// app.js
const myModule = require("./myModule");
myModule();
8. What is the difference between CommonJS and ES6 modules?
Answer:
Feature | CommonJS | ES6 Modules |
---|---|---|
Syntax | require() and module.exports | import and export |
Default | Used in Node.js | Used in modern JavaScript |
Example | const express = require("express") | import express from "express" |
9. What is an HTTP module in Node.js?
Answer: The http
module is used to create an HTTP server.
Example:
const http = require("http");
const server = http.createServer((req, res) => {
res.write("Hello, Capgemini!");
res.end();
});
server.listen(3000, () => console.log("Server running on port 3000"));
10. What is Express.js in Node.js?
Answer: Express.js is a lightweight and fast web framework for Node.js used to build RESTful APIs.
Example of an Express server:
const express = require("express");
const app = express();
app.get("/", (req, res) => {
res.send("Welcome to Capgemini!");
});
app.listen(3000, () => console.log("Server started on port 3000"));
11. What are middleware functions in Express.js?
Answer: Middleware functions handle requests and responses before they reach the final route handler.
Example:
app.use((req, res, next) => {
console.log("Middleware executed!");
next();
});
12. What is the difference between GET and POST methods in Node.js?
Answer:
Method | GET | POST |
---|---|---|
Data Type | Sent in URL | Sent in request body |
Usage | Fetch data | Send data to the server |
Example GET request:
app.get("/users", (req, res) => {
res.send("List of users");
});
Example POST request:
app.post("/users", (req, res) => {
res.send("User created");
});
13. How do you handle errors in Node.js?
Answer: Using try-catch
for synchronous code and .catch()
for promises.
Example:
try {
throw new Error("Something went wrong!");
} catch (error) {
console.log(error.message);
}
For promises:
fetchData().catch((err) => console.log(err));
14. What is a callback function in Node.js?
Answer: A callback function executes after an asynchronous operation is complete.
Example:
fs.readFile("file.txt", "utf8", (err, data) => {
if (err) throw err;
console.log(data);
});
15. What is the purpose of process.nextTick()?
Answer: process.nextTick()
executes a function immediately after the current execution completes.
Example:
process.nextTick(() => {
console.log("Executed in next tick");
});
16. What is clustering in Node.js?
Answer: Clustering allows running multiple Node.js instances to handle more requests.
Example:
const cluster = require("cluster");
if (cluster.isMaster) {
cluster.fork();
} else {
console.log("Worker process running");
}
17. What is CORS in Node.js?
Answer: CORS (Cross-Origin Resource Sharing) allows API requests from different origins.
Example using Express:
const cors = require("cors");
app.use(cors());
18. What is the difference between PUT and PATCH in REST APIs?
Answer:
Method | PUT | PATCH |
---|---|---|
Purpose | Replaces the entire resource | Updates only specific fields |
Example | Update full user data | Update only email |
19. What is JWT authentication in Node.js?
Answer: JSON Web Token (JWT) is used for secure API authentication.
Example using jsonwebtoken
:
const jwt = require("jsonwebtoken");
const token = jwt.sign({ user: "capgemini" }, "secretKey");
console.log(token);
20. What is the difference between localStorage, sessionStorage, and cookies?
Answer:
Storage | localStorage | sessionStorage | Cookies |
---|---|---|---|
Expiry | Never expires | Expires on session close | Custom expiry |
Access | Only client-side | Only client-side | Client & server |