0% found this document useful (0 votes)
13 views14 pages

Nodejs and Reactjs

The document provides a comprehensive overview of Node.js and React.js, including basic concepts, features, and real-life examples to illustrate their functionalities. It covers topics such as modules, event handling, state management, and component lifecycle in both technologies. The Q&A format aids in understanding key differences and applications of Node.js and React.js in web development.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

Nodejs and Reactjs

The document provides a comprehensive overview of Node.js and React.js, including basic concepts, features, and real-life examples to illustrate their functionalities. It covers topics such as modules, event handling, state management, and component lifecycle in both technologies. The Q&A format aids in understanding key differences and applications of Node.js and React.js in web development.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Node.

js Basic Interview Q&A (4–5 Lines


with Real-Life Examples)

General Basics
1. What is Node.js?
Node.js is a runtime that lets us run JavaScript outside the
browser, mostly for backend. It’s like giving JavaScript the
power to manage servers. Example: instead of using PHP, you
can build a web server with Node.js. Real-life: like using a
walkie-talkie outside instead of only inside a house.
console.log("Hello from Node.js");
2. Why is Node.js called asynchronous and event-driven?
Because Node.js does not wait for one task to finish before
starting another. It uses events to continue when the work is
ready. Real-life: like ordering food at a restaurant – you order
and continue talking, and food comes later.
fs.readFile("file.txt", () => console.log("Done"));
console.log("Next task");
3. Difference between Node.js and JavaScript in browsers?
In browsers, JavaScript makes web pages interactive (like
clicking buttons). In Node.js, JavaScript runs on the server to
handle backend tasks. Real-life: browser JS is like a cashier
talking to you, Node.js is like the kitchen staff preparing your
food.
// Browser: document.querySelector("h1")
// Node: fs.readFile("data.txt")
4. Role of V8 engine in Node.js?
The V8 engine converts JavaScript into machine code so
computers can run it fast. Real-life: like a translator quickly
turning English into your native language so you understand.
console.log(2 + 3); // V8 executes this quickly
5. Main features of Node.js?
Node.js is single-threaded, event-driven, and very fast. It
handles thousands of users with one thread. Real-life: like
one waiter serving many tables efficiently instead of one
waiter per table.

Modules & Packages


6. What are modules in Node.js?
Modules are blocks of reusable code you can import
anywhere. Real-life: like Lego blocks – you build once and use
in many models.
// myModule.js
exports.sayHi = () => console.log("Hi");
7. Built-in vs. user-defined modules?
Built-in modules come with Node.js (fs, http). User-defined
are made by you. Real-life: built-in is like buying ready-to-use
tools; user-defined is making your own tool.
const fs = require("fs");
const my = require("./myModule");
8. Name some core modules in Node.js.
Examples: fs, http, os, path. They handle files, servers,
operating system, etc. Real-life: like built-in apps in your
phone (camera, dialer, messages).
const os = require("os");
console.log(os.platform());
9. Difference between require() and import?
require() works in CommonJS, import in ES6 modules. Real-
life: like two ways to enter your house – a door key (require)
or a smart card (import).
const fs = require("fs"); // CommonJS
import fs from "fs"; // ES6
10. What is NPM in Node.js?
NPM (Node Package Manager) manages packages and
dependencies. Real-life: like Play Store for Node.js – you
install ready-made apps (packages).
npm install express

Event Loop & Asynchronous


11. What is the Event Loop in Node.js?
The Event Loop controls how async tasks are handled and
finished later. Real-life: like a to-do manager who reminds you
when tasks are ready.
setTimeout(() => console.log("Task done"), 1000);
console.log("First");
12. What are callbacks in Node.js?
A callback is a function called after a task is finished. Real-life:
like leaving your number at a shop and they call you when
the product is ready.
fs.readFile("data.txt", () => console.log("File read"));
13. What are Promises in Node.js?
A Promise is like a container for a value that will be ready in
the future. Real-life: like ordering something online and
waiting for delivery.
Promise.resolve("Done").then(console.log);
14. What is async/await in Node.js?
Async/await makes async code look simple and readable.
Real-life: like saying, “I’ll wait here until my coffee is ready”
instead of setting reminders.
async function test(){
let data = await Promise.resolve("Hello");
console.log(data);
}
test();
15. Difference between synchronous and asynchronous
programming?
Synchronous waits step by step. Asynchronous continues
without waiting. Real-life: Sync = standing in line; Async =
getting a token and waiting while doing other work.
setTimeout(()=>console.log("A"),1000);
console.log("B");

File System & Streams


16. How to read a file in Node.js?
You use fs.readFile to read files. Real-life: like opening a book
and reading its content.
fs.readFile("data.txt", "utf8", (err, data) => console.log(data));
17. How to write to a file in Node.js?
You use fs.writeFile to create or replace a file. Real-life: like
writing a new diary entry.
fs.writeFile("new.txt", "Hello World", () =>
console.log("Saved"));
18. What are streams in Node.js?
Streams allow reading/writing data in small parts instead of
all at once. Real-life: like watching YouTube without
downloading the entire video.
fs.createReadStream("big.txt").pipe(process.stdout);
19. Types of streams in Node.js?
Four types: Readable, Writable, Duplex, Transform. Real-life:
like water pipes – one-way, out, both ways, and filtered.
20. What is a buffer in Node.js?
Buffer stores temporary binary data. Real-life: like a plate
holding food before you eat it.
let buf = Buffer.from("Hello");
console.log(buf);

Server & HTTP


21. How do you create a simple server in Node.js?
You use the http module. Real-life: like opening a food stall to
serve people.
const http = require("http");
http.createServer((req, res)=>res.end("Hello")).listen(3000);
22. What is Express.js and why is it used?
Express.js is a framework for building web servers easily.
Real-life: like using a microwave instead of cooking from
scratch.
const express = require("express");
const app = express();
app.get("/", (req,res)=>res.send("Hello"));
23. What is middleware in Express.js?
Middleware are functions that run before sending a
response. Real-life: like a security check before entering a
mall.
app.use((req,res,next)=>{console.log("Middleware");
next();});
24. What is REST API in Node.js?
REST API uses HTTP to perform CRUD operations. Real-life:
like ordering food (Create), checking menu (Read), changing
order (Update), canceling order (Delete).
app.get("/users", (req,res)=>res.json(["John"]));
25. What is the difference between HTTP and HTTPS?
HTTP is normal, not secure. HTTPS is secure with SSL. Real-
life: HTTP is like a normal letter, HTTPS is like a letter in a
locked box.

Process & Environment


26. What is process object in Node.js?
The process object gives details about the running program.
Real-life: like knowing your car’s engine status while driving.
console.log(process.pid);
27. How do you access environment variables in Node.js?
Use process.env. Real-life: like customizing your app with
settings (temperature preference in AC).
console.log(process.env.PORT);
28. What is package.json in Node.js?
It stores project info like dependencies and scripts. Real-life:
like an identity card that tells about you.
{
"name": "myapp",
"dependencies": { "express": "^4.18.0" }
}
29. What is package-lock.json in Node.js?
It locks exact versions of dependencies. Real-life: like fixing
the recipe so everyone cooks the same way.
{
"express": { "version": "4.18.0" }
}
30. What is REPL in Node.js?
REPL (Read-Eval-Print-Loop) is an interactive shell to test code
quickly. Real-life: like a calculator where you try small
calculations instantly.
node
> 2+3
5
React.js Basic Interview Q&A (With
Examples)

General Basics
1. What is React.js?
React.js is a JavaScript library for building user interfaces,
mainly for single-page applications. It helps developers build
reusable UI components. Example: making a login form that
can be reused on multiple pages.
function Welcome(){ return <h1>Hello!</h1>; }
Real-life Example: Like Lego blocks, you can build a big toy
(app) using small reusable pieces (components).
2. What are components in React?
Components are independent and reusable pieces of UI in
React. They can be functional (simple) or class-based (with
state). Example: a button, header, or footer.
function Button(){ return <button>Click</button>; }
Real-life Example: Like a car has small parts (wheels, engine),
React apps have components.
3. What is JSX in React?
JSX is a syntax that lets us write HTML inside JavaScript. It
makes UI code easier to read and write. Example:
const element = <h1>Hello JSX</h1>;
Real-life Example: Like mixing English with emojis , JSX
mixes HTML with JavaScript.
4. Difference between functional and class components?
Functional components are simple functions that return UI.
Class components are more powerful, supporting state and
lifecycle methods. Today, hooks make functional components
more popular.
function Hello(){ return <h1>Hi</h1>; }
Real-life Example: Functional components are like scooters
(simple), class components are like cars (feature-rich).
5. What is the virtual DOM in React?
The virtual DOM is a lightweight copy of the real DOM. React
updates it first, then updates only the changed parts in the
real DOM, making apps fast.
Real-life Example: Like editing a draft copy of a document
before final printing.

State & Props


6. What are props in React?
Props are inputs passed to components, making them
reusable. Example:
function Welcome(props){ return <h1>Hello
{props.name}</h1>; }
Real-life Example: Like giving different toppings to the same
pizza base.
7. What is state in React?
State is used to manage data that changes inside a
component. Example: a counter that increases on click.
const [count, setCount] = useState(0);
Real-life Example: Like a water bottle showing different levels
when filled or emptied.
8. Difference between props and state?
Props are external and read-only, while state is internal and
changeable. Together, they control component behavior.
Real-life Example: Props are like a gift you receive (can’t
change), state is like your mood (changes often).
9. What are hooks in React?
Hooks let functional components use state and other
features. Common hooks: useState, useEffect. Example:
const [name, setName] = useState("John");
Real-life Example: Hooks are like power-ups in games that
give extra abilities.
10. What is useState hook?
useState lets you add state to a functional component.
Example:
const [count, setCount] = useState(0);
Real-life Example: Like keeping a scorecard in a cricket match.

Lifecycle & Rendering


11. What is useEffect hook?
useEffect allows side effects (like fetching data, timers). It
runs after rendering. Example:
useEffect(()=>{ console.log("Mounted"); }, []);
Real-life Example: Like watering plants after placing them in a
pot.
12. What is component lifecycle in React?
It is the stages a component goes through: mounting,
updating, unmounting. Example: creating, changing, then
removing a profile card.
Real-life Example: Like human life – birth, growth, death.
13. What is conditional rendering in React?
Showing UI based on conditions. Example:
{isLoggedIn ? <h1>Welcome</h1> : <h1>Please Login</h1>}
Real-life Example: Like showing “Open” or “Closed” board
outside a shop.
14. What are lists and keys in React?
Lists display multiple items, and keys help React track
changes. Example:
items.map((i)=> <li key={i}>{i}</li>)
Real-life Example: Like roll numbers in a classroom to identify
students.
15. What is reconciliation in React?
Reconciliation is how React updates the DOM by comparing
the virtual DOM with the real one.
Real-life Example: Like updating only changed answers in a
test instead of rewriting the entire sheet.

Advanced
16. What are controlled components?
Input elements controlled by React state. Example:
<input value={name}
onChange={e=>setName(e.target.value)} />
Real-life Example: Like a teacher controlling students’
activities step by step.
17. What are uncontrolled components?
Inputs handled by the DOM itself, not React. Example:
<input defaultValue="Hello" />
Real-life Example: Like students doing homework without
teacher’s supervision.
18. What is React Router?
A library for navigation between pages in React apps.
Example:
<Route path="/about" element={<About />} />
Real-life Example: Like Google Maps guiding you through
different roads (pages).
19. What is Redux?
Redux is a state management library for React. It stores all
data in a single place (store).
Real-life Example: Like a library storing all books in one
central place for everyone to use.
20. Difference between React and Angular?
React is a library, Angular is a full framework. React is
lightweight and flexible, Angular is more structured and
heavy.
Real-life Example: React is like ordering à la carte, Angular is
like a full buffet.

You might also like