Awp Gtu
Awp Gtu
• Node.js is an open-source and cross-platform runtime environment for executing JavaScript code
outside a browser.
• Node.js is used to build back-end services like APIs for Web Apps or Mobile Apps.
• It’s utilized in production by large companies such as PayPal, Uber, Netflix, Walmart, and many others.
• Example:
// Import the http module
const http = require('http');
// Create a server
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Welcome to the Node.js Tutorial');
});
2. Fast Performance
• Ideal for chat apps, online games, and live collaboration tools.
• It can handle many users talking to the server at once — quickly and smoothly.
6. Cross-Platform
• Node.js is perfect for small, fast services that talk to each other (called microservices).
• Tools like Express.js make it easy to build RESTful APIs.
8. Real-Time Communication
• Supports WebSockets, allowing two-way communication between the server and the browser.
• Great for apps that need live updates (like notifications or stock price changes).
• Node.js works really well with JSON, which is the main format used for APIs and data exchange in web
apps.
Browser Games
• Ideal for creating real-time applications.
• Utilizes Socket.io and HTML for interactive game development.
• Enables seamless real-time communication and responsive design.
Collecting Data Inputs
• Efficiently collects data from various sources.
• Handles form data collection from browsers.
• Sends data to the backend for storage in databases.
• Enables fetching and processing of stored data.
Streaming Media
• Facilitates fast and efficient media uploading.
• Handles processing of audio and video files.
• Ensures quick upload times and high-speed access.
• Crucial for real-time media processing and streaming.
Online Chat Rooms
• Creates platforms for text chat, voice sharing, and media sharing.
• Handles real-time data for instant communication.
• Ideal for gaming chat rooms and social media platforms.
MERN Stack
• Part of the MERN stack (MongoDB, Express.js, React.js, Node.js).
• Serves as the server-side component.
• Provides efficient data handling and backend integration with MongoDB.
Real-Time Applications
• Suitable for highly scalable and low latency applications.
• Used by platforms like LinkedIn and PayPal.
• Event-driven architecture for quick data processing and response times.
Creation of APIs
• Develops APIs for backend operations.
• Facilitates communication between frontend and backend.
• Handles data processing and logic execution.
• Supports asynchronous operations for robust and scalable API development.
ANS:
1. Uppercase Filter
• Add uppercase filter to an expression using pipe character. Here we've added uppercase filter to
print student name in all capital letters.
• Example:
Enter first name:<input type = "text" ng-model = "student.firstName">
Enter last name: <input type = "text" ng-model = "student.lastName">
Name in Upper Case: {{student.fullName() | uppercase}}
2. Lowercase Filter
• Add lowercase filter to an expression using pipe character. Here we've added lowercase filter to
print student name in all lowercase letters.
• Example:
Enter first name:<input type = "text" ng-model = "student.firstName">
Enter last name: <input type = "text" ng-model = "student.lastName">
Name in Lower Case: {{student.fullName() | lowercase}}
3. Currency Filter
• Add currency filter to an expression returning number using pipe character. Here we've added
currency filter to print fees using currency format.
• Example:
Enter fees: <input type = "text" ng-model = "student.fees">
fees: {{student.fees | currency}}
4. Filter
• To display only required subjects, we use subjectName as filter.
• Example:
Enter subject: <input type = "text" ng-model = "subjectName">
Subject:
<ul>
<li ng-repeat = "subject in student.subjects | filter: subjectName">
{{ subject.name + ', marks:' + subject.marks }}
</li>
</ul>
5. OrderBy Filter
• To order subjects by marks, we use orderBy marks.
• Example:
Subject:
<ul>
<li ng-repeat = "subject in student.subjects | orderBy:'marks'">
{{ subject.name + ', marks:' + subject.marks }}
</li>
</ul>
• A REST (REpresentational State Transfer) API is a web service that follows the principles of REST
architecture to interact between clients and servers over HTTP.
• It uses standard HTTP methods (GET, POST, PUT, DELETE) to perform CRUD (Create, Read, Update,
Delete) operations on resources, and data is typically transferred in JSON or XML format.
Principles of REST API
REST APIs are built on six fundamental principles that define their architecture and functionality:
• Statelessness: Each request from a client to the server must contain all the necessary information, and
the server does not store session-related data.
• Client-Server Architecture: The client and server are separate entities, allowing for independent
development and scalability.
• Uniform Interface: A consistent way of accessing resources, typically via standardized HTTP methods
(GET, POST, PUT, DELETE).
• Cacheability: Responses from the server should indicate whether they can be cached to improve
performance.
• Layered System: The architecture should support multiple layers (such as load balancers,
authentication servers, and data storage) without affecting the client-server interaction.
• Code on Demand (Optional): The server can send executable code (like JavaScript) to the client to
enhance functionality, though this is rarely used.
HTTP Methods Used in API
In RESTful APIs, HTTP methods define the actions to be performed on resources. Each HTTP method
corresponds to a specific operation in the CRUD (Create, Read, Update, Delete) cycle. Here’s an explanation of
the commonly used HTTP methods:
GET Method
The GET method is used to retrieve an existing resource from the server. The server responds with the
resource's data, often in JSON or XML format. It is used to read the data.
HTTP GET http://example.com/users
HTTP GET http://example.com/users/123
POST Method
The POST method is used to create a new resource on the server. It sends data to the server as part of the
request body, typically in JSON or XML format. It is used to create a new resource on the server.
HTTP POST http://example.com/users
HTTP POST http://example.com/users/123
PUT Method
The PUT method is used to update an existing resource on the server. It requires the client to send the updated
data in the request body. It is used to update the data.
HTTP PUT http://example.com/users/123
HTTP PUT http://example.com/users/123/name/Anjali
PATCH Method
The PATCH method is used to apply partial modifications to a resource. Unlike PUT, which typically updates
the entire resource, PATCH only sends the changes to be made, making it more efficient in certain scenarios. It
is used to partially update the data on the server.
HTTP PATCH http://example.com/users/123
HTTP PATCH http://example.com/users/123/name/Anjali
DELETE Method
The DELETE method is used to delete a resource from the server. Once executed successfully, it usually returns
a status code indicating the deletion has been completed, such as 200 OK or 204 No Content. It is used to delete
the data.
HTTP DELETE http://example.com/users/123
HTTP DELETE http://example.com/users/123/name/Ravi
The Network module in Node.js provides the ability to work with network operations such as creating servers
and clients for TCP (Transmission Control Protocol) and IPC (Inter-Process Communication).
Though Node.js does not have a module named strictly “network”, these capabilities are available through the
built-in net module.
Function/Method Description
net.createServer() Creates a TCP server
EXAMPLE:
console.log('Received:', data.toString());
});
});
server.listen(5000, () => {
});
ANS:A stream in Node.js is a way to handle reading or writing data sequentially—chunk by chunk—
instead of loading it all into memory at once.
Types of Streams
• AngularJS is well-suited for building SPAs where content updates dynamically without reloading the
entire page.
• Example: Gmail, Facebook-like interfaces.
• AngularJS allows two-way data binding, making it ideal for applications that need to update the UI in
real time based on user input or data changes.
3. CRUD Applications
• Used to build apps that perform Create, Read, Update, Delete operations.
• Example: Employee management systems, contact managers, admin panels.
4. Form-Based Applications
• With built-in support for form validation, AngularJS simplifies creating applications with dynamic
forms and user inputs.
• Example: Registration forms, feedback forms, and login forms.
5. Real-Time Applications
• You can build lightweight and efficient CMS tools using AngularJS, especially when combined with
APIs.
• Example: Blog or portfolio site admin panels.
7. E-commerce Applications
• Many internal company tools use AngularJS for managing large data and user interactions.
• Example: Project tracking tools, employee portals.
MongoDB is a popular, open-source NoSQL database designed for handling large volumes of unstructured
or semi-structured data. Instead of storing data in tables like traditional relational databases, MongoDB stores
data in flexible, JSON-like documents.
1. Document-Oriented
a. Data is stored in collections (similar to tables) and each item is a document (similar to a row).
b. Documents use BSON (Binary JSON), which supports nested data and arrays.
2. Schema-less
a. Collections don’t require a fixed schema.
b. Each document in a collection can have a different structure.
3. High Performance
a. Designed for high read/write throughput.
b. Supports indexing, replication, and horizontal scaling.
4. Scalability
a. Built to scale across many servers using sharding.
b. Suitable for big data applications.
5. Rich Query Language
a. Supports powerful queries using JavaScript-like syntax.
b. Example:db.users.find({ age: { $gt: 25 } });
6. Integration with Node.js
a. MongoDB works well with JavaScript-based environments like Node.js using drivers like
Mongoose or the native MongoDB Node.js driver.
ANS:
Cookies
Characteristics:
Sessions
Characteristics:
app.use(session({
secret: 'mysecret',
resave: false,
saveUninitialized: true
}));
Q: Write Node JS programs for database connectivity with MongoDB including insert operation in
MySQL database.
Q: Create a webpage using Angular JS that displays details of students'objects (such as Enrollment No.,
Name, Semester, Branch, MobileNumber, Email Address, Address etc.) in a tabular format with
appropriate CSS effects.
Q: Create a HTML form using bootstrap controls that will accept EnrollmentNo., Name, Semester,
Branch, Mobile Number, Email, Address etc. fromthe student, combine and display them on the
page when button is clickedalso validate an Email address using Javascript.
Q: Explain piping and chaining of streams with suitable example.
ANS:
Piping:
• Piping is a method used to connect the output of one stream to the input of another.
• It’s commonly used to read from a readable stream and write to a writable stream without manually
handling events like data, end, etc.
• Think of it like:
Source → Transform (optional) → Destination
Chaining:
Here:
ANS: The event loop in Node.js is a mechanism that allows asynchronous tasks to be handled efficiently
without blocking the execution of other operations. It:
1. Timers Phase: This phase processes timers that have been set using setTimeout() and setInterval().
1. Pending Callbacks: This phase executes I/O-related callbacks that were deferred from the previous
loop cycle.
2. Idle, Prepare (Internal use only):This phase is used internally by Node.js for background tasks.
3. Poll Phase (Main Phase): The Poll phase executes most of the tasks like- I/O, file reading, HTTP
requests and much more.
4. Check Phase: This phase processes any setImmediate() callbacks that have been added to the message
queue.
5. Close Callbacks Phase: This phase executes callbacks for closed connections like sockets, streams, and
event emitters.
• Error-first callback in Node.js is a function that returns an error object whenever any successful data is
returned by the function.
• The first argument is reserved for the error object by the function. This error object is returned by
the first argument whenever any error occurs during the execution of the function.
• The second argument is reserved for any type of successful data returned by the function. The
error object is set to null when no error occurs.
• EXAMPLE:
Buffer in Node is a built-in object used to perform operations on raw binary data. The buffer class allows
us to handle the binary data directly.
Buffer Methods:
No Method Description
7 Buffer.copy(buffer,subsection
It copies data from one buffer to another.
size)
8 Buffer.slice(start,
It returns the subsection of data stored in a buffer.
end=buffer.length)
REPL is like a JavaScript playground in your terminal. If you type the code, REPL runs it, shows you the result,
and then waits for your next command. It's a loop:
• READ: You type some JavaScript code into the terminal, and REPL reads what you typed.
• EVAL: REPL runs (evaluates) your code.
• PRINT: REPL shows you the result of your code.
• LOOP: REPL goes back to step 1, waiting for you to type more code. This loop continues until you quit
REPL.
The REPL has started and is demarcated by the '>' symbol. Various operations can be performed on the REPL.
Below are some of the examples to get familiar with the REPL environment.
Example:
Q: Write code to perform update and delete operations on Employee database using Node.js and
MongoDB.