IT3501 – FULL STACK WEB DEVELOPMENT
UNIT 1 – Answer Key
1. Define User
In full stack web development, a User is the person or entity interacting with the web application through a client device (web browser, mobile app, etc.).
- Example: In an e-commerce website, a user browses products, adds them to the cart, and makes a purchase.
2. MVC Architecture Diagram with Small Note
MVC (Model–View–Controller) is a software design pattern that separates application logic into three components:
+-----------+ +-----------+ +-----------+
| Model | <----> | Controller| <----> | View |
+-----------+ +-----------+ +-----------+
Explanation:
- Model – Manages application data and business logic.
- View – Handles UI and presentation.
- Controller – Acts as an interface between Model and View.
3. Define MERN and MEAN Stack
- MERN Stack = MongoDB, Express.js, React.js, Node.js – Used for building full stack JavaScript applications.
- MEAN Stack = MongoDB, Express.js, Angular, Node.js – Similar to MERN but uses Angular for the front end.
4. What is REST API?
REST API (Representational State Transfer) is an architectural style for designing networked applications where data is accessed and manipulated using HTTP methods (GET, POST, PUT, DELETE).
- Example:
GET /usersreturns user data in JSON format.
5. Components of MVC Architecture
- Model – Manages data and logic.
- View – Displays data to the user.
- Controller – Processes user input and updates model/view.
6. Features of NoSQL
- Schema-less data storage
- Supports unstructured & semi-structured data
- Horizontal scalability
- High performance for big data applications
- Example: MongoDB stores documents in JSON format.
7. Install and Verify Node.js
Installation Steps:
- Visit nodejs.org and download installer.
- Install with default settings.
- Verify version:
node -v npm -v
8. Define Callbacks in Node.js
A callback is a function passed as an argument to another function, executed after the completion of an operation.
Use in Node.js: Handles asynchronous tasks like reading files or API calls.
Example:
fs.readFile('file.txt', (err, data) => {
if (err) throw err;
console.log(data.toString());
});
9. What is a Web Development Framework?
A web development framework is a pre-built collection of libraries and tools that provides structure for building web applications.
- Example: Express.js in Node.js.
10. What is Express in Full Stack?
Express.js is a lightweight Node.js framework used for building server-side applications and REST APIs.
11. Primitive Types in Node.js
- String
- Number
- BigInt
- Boolean
- Undefined
- Symbol
- Null
12. Callbacks in Node.js
(Already defined in #8 – same concept)
13. What is Full Stack Web Development?
Full stack web development refers to the process of designing and developing both frontend and backend of a web application.
- Example: Using React for frontend and Node.js for backend.
14. Roles of Backend Services
- Handle business logic
- Manage database operations
- Authenticate users
- Process API requests/responses
15. Callbacks and Events in Node.js
- Callbacks – Triggered when an async task completes.
- Events – Triggered by an EventEmitter object when a specific action occurs.
16. Timer Methods in Node.js
setTimeout(fn, ms)– Executes function after delay.setInterval(fn, ms)– Repeats function at intervals.setImmediate(fn)– Runs after current event loop.process.nextTick(fn)– Runs before next event loop phase.
17. Define Asynchronous Event Driven Architecture
In Node.js, operations are non-blocking and handled via events/callbacks, allowing multiple tasks to run without waiting for previous ones to finish.
18. Simple Node.js Server
const http = require('http');
http.createServer((req, res) => {
res.write('Hello World');
res.end();
}).listen(3000);
19. Simple Calculator in Node.js
const readline = require('readline').createInterface({
input: process.stdin, output: process.stdout
});
readline.question('Enter a+b: ', expr => {
console.log(eval(expr));
readline.close();
});
20. Publish Package to NPM
- Create
package.json. - Run
npm login. - Run
npm publish.
21. Use NPM Module
npm install lodash
const _ = require('lodash');
console.log(_.capitalize('hello'));
22. Compare Event Callbacks & Threaded Model
- Event Callbacks: Single-threaded, async, scalable.
- Threaded Model: Multi-threaded, blocking, more memory usage.
23. Blocking I/O
Blocks execution until operation completes.
Example:
let data = fs.readFileSync('file.txt');
24. Node.js Event Model Diagram
Event Loop --> Event Queue --> Callback Execution
25. Adding Work to Event Queue
setTimeout()setImmediate()process.nextTick()- I/O events
26. Definitions
- Web Client – Requests data (browser).
- User – Person using application.
- Web Server – Responds to requests.
- MEAN Stack – MongoDB, Express, Angular, Node.
- MERN Stack – MongoDB, Express, React, Node.
- Node.js – JavaScript runtime for backend.
- Events – Signals emitted by an emitter.
- Listeners – Functions that handle events.
- NPM – Node Package Manager.
- Callback – Function called after a task.
27. Console Time Example
console.time('test');
for(let i=0; i<1000000; i++) {}
console.timeEnd('test');
28. Blocking of I/O
When execution waits for I/O to complete before continuing.
29. Callback Implementation Diagram
Function Call --> Async Operation --> Callback Function Executed
30. Features of Node.js
- Event-driven
- Non-blocking I/O
- Single-threaded
- Cross-platform
- NPM ecosystem
1. Different Ways of Adding Work to the Event Queue
In Node.js, tasks can be added to the event queue using:
setTimeout(callback, ms)– Runs callback after delay.setInterval(callback, ms)– Runs callback repeatedly after each delay.setImmediate(callback)– Runs callback after current poll phase.process.nextTick(callback)– Runs callback before the next event loop phase.- I/O Event Callbacks – e.g.,
fs.readFile()completion.
2. Definitions
- Web Client – The application/device (browser, mobile app) that sends requests to a server.
- User – The person using the web client to interact with the application.
- Web Server – A computer/program that processes client requests and sends responses.
- MEAN Stack – MongoDB, Express.js, Angular, Node.js.
- MERN Stack – MongoDB, Express.js, React.js, Node.js.
- Node.js – JavaScript runtime environment for server-side programming, built on Chrome’s V8 engine.
- Events – Signals emitted when an action occurs in Node.js (e.g., file read complete).
- Listeners – Functions that handle/act upon events.
- NPM (Node Package Manager) – Tool to install, update, and manage Node.js packages.
- Node Package Module – A reusable JavaScript library published via NPM.
- Callback – A function passed to another function, executed after an operation completes.
3. Add Work to Event Queue Example
setTimeout(() => console.log("Timeout task"), 1000);
setImmediate(() => console.log("Immediate task"));
process.nextTick(() => console.log("Next tick task"));
4. Console Time and Console Time End Example
console.time('loop');
for (let i = 0; i < 1e6; i++) {}
console.timeEnd('loop');
Output: Displays the time taken to execute the loop.
5. Define Blocking of I/O
Blocking I/O means program execution is paused until the I/O operation completes.
Example:
let data = fs.readFileSync('file.txt'); // Blocks until file read finishes
6. Callback Implementation Diagram
Function Call
|
v
Start Async Task
|
v
Task Completes
|
v
Callback Function Executed
7. Features of Node.js (5 lines)
- Asynchronous & Event-Driven – Executes tasks without waiting.
- Non-Blocking I/O – Improves performance for multiple requests.
- Single-Threaded Model – Uses event loop for scalability.
- Cross-Platform – Runs on Windows, macOS, Linux.
- Rich NPM Ecosystem – Thousands of pre-built packages available.
1. Web Client
A web client is the application (usually a browser like Chrome, Firefox, or a mobile app) that sends HTTP requests to a web server to fetch or send data. It displays the server’s response in a user-friendly format (UI).
- In full stack development, the web client runs the frontend code (HTML, CSS, JS).
- Example: When you visit
www.amazon.comin Chrome, your browser is the web client sending requests to Amazon’s servers.
2. User
A user is the person or system that interacts with the web application via a client device (browser, app). Users generate requests by clicking links, filling forms, or calling APIs.
- In full stack development, the goal is to create a seamless experience for the user.
- Example: A customer shopping online is a user making requests like “view product” or “place order”.
3. Web Server
A web server is software/hardware that listens for client requests over HTTP, processes them, and sends back responses (HTML, JSON, images, etc.).
- In full stack, Node.js or Apache can act as a web server.
- Example: Node.js
http.createServer()method creates a simple web server that sends back “Hello World” on a request.
4. MEAN Stack
The MEAN stack is a full stack JavaScript framework combination: MongoDB (database), Express.js (backend framework), Angular (frontend framework), Node.js (runtime environment).
- It allows building end-to-end apps using JavaScript only.
- Example: An Angular app fetching data from Express API stored in MongoDB.
5. MERN Stack
The MERN stack is similar to MEAN but uses React.js instead of Angular. Components: MongoDB, Express.js, React.js, Node.js.
- Preferred for modern, dynamic, component-based UIs.
- Example: A React app displaying products with data from a Node.js API connected to MongoDB.
6. Node.js
Node.js is an open-source, cross-platform JavaScript runtime environment built on Chrome’s V8 engine that allows running JS outside the browser.
- Used for building scalable, event-driven backend services.
- Example: Creating a REST API with Express.js in Node.js.
7. Events
In Node.js, events are signals emitted when something happens (e.g., file read complete, HTTP request received).
- Handled by the
eventsmodule usingEventEmitter. - Example:
emitter.emit('start');
8. Listeners
A listener is a function that waits for and responds to a specific event.
- Added using
.on()or.addListener()methods. - Example:
emitter.on('start', () => console.log('Started'));
9. NPM (Node Package Manager)
NPM is a package manager for Node.js used to install, update, and manage third-party libraries.
- Comes bundled with Node.js installation.
- Example:
npm install express
10. Node Package Module
A Node package module is a reusable piece of JavaScript code published to the NPM registry that can be imported into other applications.
- Example:
lodashfor utility functions.
11. Callback
A callback is a function passed into another function to be executed later, often after an asynchronous task completes.
- Used heavily in Node.js for non-blocking I/O.
- Example:
fs.readFile('data.txt', (err, data) => { console.log(data.toString()); });
Adding Work to the Event Queue
In Node.js, work is added to the event queue by:
- Using blocking I/O library calls (e.g., write to file, connect to database).
- Adding built-in event listeners (e.g.,
http.request,server.connection). - Creating custom event emitters and listeners.
- Using process.nextTick() to schedule work in the next event loop cycle.
- Using timers to run tasks after a delay or at intervals.
FEATURES OF NODE.JS
Asynchronous & Non-blocking I/O
Node.js uses an event-driven, non-blocking I/O model, allowing efficient concurrent request handling without waiting for operations to complete. This is achieved using the event loop.
Single-threaded
Node.js runs on a single thread, but the event loop manages multiple operations by offloading I/O tasks to the system kernel.
npm (Node Package Manager)
Node.js includes npm, a large ecosystem of open-source libraries and tools that simplify development and extend functionality.
Use Cases
Node.js is ideal for building REST APIs, real-time applications (chat apps), microservices, and data-intensive applications.
