Professional Documents
Culture Documents
Industrial Training
ReportOn
“Node JS”
Submitted for partial fulfilment of the requirements for the award of
the degree of
Bachelor of
Technology In
Electrical Engineering
Session : 2023-24
CANDIDATE DECLARATION
Lalit soni
7 EE B
20ESKEE061
I would like to show gratitude towards my teachers and the trainers for the
opportunity given and help to complete my training within the time allotted.
This training would not have been completed without the support of my teachers and
parents. Therefore, I would like to thank our Incharge, Industrial Training, Mr. Ajay
Bhardwaj, Assistant Professor, Department of Electrical Engineering, Swami
Keshvanand Institute of Technology, Management & Gramothan, Jaipur for
extending his cordial support throughout the training completion. I would also like to
thank Dr. Sarfaraz Nawaz, Head Of Department of Electrical Engineering, Swami
Keshvanand Institute of Technology, Management & Gramothan, Jaipur for
giving me enough time to complete the training.
I would like to extend my thanks to Dr. S. L. Surana, Director (Academics) and Dr.
Ramesh Kumar Pachar, Principal, Swami Keshvanand Institute of Technology,
Management & Gramothan, Jaipur for their motivation throughout our college time.
Our efforts made together led to the effective completion of the training.
It may not be possible for me to acknowledge the support of all my friends, but I am
thankful to all other trainees for their valuable ideas and support during the training
period.
LALIT SONI
7 EE B
20ESKEE061
Main Page
Certificate
Candidate Declaration
Acknowledgement
Contents
Abstract
Chapter name
1. History
2. Introduction
2.1 NodeJS
2.2 Purpose and goals of NodeJS
3. Architecture of NodeJS
3.1 Overview of the event-Driven, Non-Blocking I/O mode
3.2 NodeJS process Architecture and Asynchronous programming
in NodeJS
4. Features of NodeJS
4.1 Source-side JavaScript
5. Express.JS Framework
5.1 Introduction
6. Database Connectivity
6.1 connecting database using NodeJS
Conclusion
Reference
Unfortunately,
Netscape LiveWire wasn't very successful and server-side Javascript wasn't popularized
until recently, by the introduction of Node.js. One key factor that led to the rise of Node.js
was the timing. Just a few years earlier, JavaScript had started to be considered as a more
serious language, thanks to "Web 2.0"applications (such as Flickr, Gmail, etc.) that showed
the world what a modern experience on thewebcould be like.
JavaScript engines also became considerably better as many browsers competed to offer
users the best performance. Development teams behind major browsers worked hard to
offer better support for JavaScript and find ways to make JavaScript run faster. The engine
hat Node.jsusesunderthehood, V8 (alsoknown as Chrome V8 forbeingtheopen-source JavaScript
engine of The Chromium Project), improved significantly due to this competition.
Node.js happened to be built in the right place and right time, but luck isn't the only reason
why it is popular today. It introduces a lot of innovative thinking and approaches for
JavaScript server-side development that has already helped so many developers
2.1 NODE.JS
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast and
scalable network applications. Node.js uses an event-driven, non-blocking I/O model that
makes it lightweight and efficient, perfect for data-intensive real-time applications that run
across distributed devices. Node.js is an open source, cross-
Linux. Node.js also provides a rich library of various JavaScript modules which simplifies th
e development of web applications using Node.js to a great extent.
Large Ecosystem: Node.js comes with a vibrant and extensive ecosystem of packages
and libraries, facilitated by the Node Package Manager (NPM). This makes it easy for
developers to find and use pre-built modules to accelerate development.
Community Support: Node.js has garnered strong community support over the years.
This active community contributes to the continuous improvement of Node.js, provides
assistance through forums and discussions, and creates a collaborative environment for
developers.
Node.js adopts an event-driven, non-blocking I/O model that sets it apart from
traditional server-side technologies. The fundamental concept revolves around
handling operations asynchronously, allowing the server to continue processing other
tasks while waiting for non-blocking I/O operations to complete.
Libuv Library: Node.js relies on the Libuv library to handle asynchronous I/O
operations. Libuv provides a unified API for asynchronous operations on
various operating systems, including Windows, Linux, and macOS.
Traditionally, JavaScript was primarily associated with client-side scripting for web
browsers. Node.js extends the use of JavaScript to the server side, allowing developers to use
a single programming language, JavaScript, for both client and server applications. This
unification simplifies development, promotes code reuse, and facilitates the sharing of code
between the server and client. It also enables developers with expertise in JavaScript to work
on full-stack development seamlessly.
Node Package Manager (NPM) is a powerful package manager and ecosystem for Node.js. It
simplifies the process of discovering, installing, and managing third-party libraries and tools.
Key aspects of NPM include:
Scripts: NPM enables the execution of scripts defined in the package.json file,
automating common development tasks. This is particularly useful for tasks like
testing, building, and deployment.
Cross-platform Development
This cross-platform capability is valuable for teams working in diverse environments and for
deploying applications on servers with different operating systems. It fosters flexibility and
reduces the challenges associated with platform-specific development.
Node.js follows a single-threaded event loop model for handling concurrency. The event loop
efficiently manages multiple connections without creating additional threads. Key aspects of
the single-threaded event loop include:
Non-Blocking I/O: The single-threaded event loop enables Node.js to handle a large
number of concurrent connections without waiting for each I/O operation to complete.
Asynchronous operations allow the server to initiate tasks and continue processing
other events while waiting for I/O to finish.
Responsive Applications: The event loop ensures that Node.js remains responsive,
even under heavy loads. It processes events sequentially, preventing any single long-
running task from blocking the entire application.
Express.js Overview:
Routing Simplicity: Express simplifies URL routing, making it easy to define routes
for different HTTP methods and URL patterns. This enhances code organization and
readability.
Setting Up: Install Express using NPM and set up the basic application structure,
including server file, middleware configuration, and route definitions.
Routing: Define routes for various HTTP methods and URL patterns. Implement
route handlers to process requests and generate responses.
Error Handling: Express provides mechanisms for error handling, including custom
error handlers and middleware functions dedicated to handling errors gracefully.
Middleware in
Express.js Middleware
Functions:
Definition: Middleware functions have access to the request (`req`) and response
(`res`) objects and can manipulate them. They also have access to the next
middleware function in the cycle.
Authentication:
Verify user credentials before granting access to specific routes or resources.
Error Handling:
Catch and handle errors during the request-response cycle to prevent application
crashes.
Data Parsing:
Middleware can parse incoming data (JSON, URL-encoded) for easier handling.
CODE:
// Route handler
app.get('/', (req, res) =>
{
res.send('Hello, Express!');
});
app.listen(3000, () => {
console.log('Server is listening on port 3000');
});
Node.js provides various modules and drivers for connecting to databases. The most
common approach is to use a dedicated database driver or an Object-Relational
Mapping (ORM) library.
Popular database drivers include mysql for MySQL, mongodb for MongoDB, pg for
PostgreSQL, and others. These drivers enable Node.js applications to establish
connections, execute queries, and interact with the respective databases.
Popular Database
Options 1.MongoDB:
A NoSQL database that stores data in JSON-like BSON format. Known for its flexibility,
scalability, and ability to handle unstructured data. Widely used for document-oriented
databases in applications with varying data structures.
2. MySQL:
3. PostgreSQL:
4. SQLite:
A self-contained, serverless, and zero-configuration SQL database engine. Known for its
simplicity, lightweight nature, and ease of integration. Suitable for small to medium-sized
applications or embedded systems.
ORM in Node.js:
Eliminates the need for raw SQL queries, making database operations more intuitive
and portable across different database systems.
Developers can work with objects and classes in their code, abstracting away the
specifics of the underlying database.
Portability:
The same code can be used with different databases by changing the ORM
configuration.
Productivity: Developers can focus more on application logic, and the ORM takes
care of generating and executing SQL queries.
1. Asynchronous Code: Leverage Node.js's non-blocking I/O model to ensure that the
application remains responsive even when handling multiple concurrent operations.
2. Code Optimization: Optimize your code for performance by identifying and refactoring
bottlenecks. Tools like profilers and performance monitoring libraries can help in this
process.
3. Caching: Implement caching mechanisms, both at the application and database levels, to
reduce redundant computations and queries.
4. Compression: Use compression middleware to reduce the size of data sent between the
server and clients, improving overall performance, especially for web applications.
1. Load Balancing: Distribute incoming network traffic across multiple servers to ensure no
single server is overwhelmed. Load balancers enhance fault tolerance and enable horizontal
scaling.
2. Horizontal Scaling: Add more machines to your infrastructure to handle increased load.
This is achieved through load balancing, where incoming requests are distributed among
multiple servers.
4. Reverse Proxy: Use a reverse proxy, such as Nginx or HAProxy, to distribute incoming
requests among multiple Node.js instances. This helps in load balancing and provides
additional security features.
2. Database Scaling: Choose databases that support horizontal scaling. Shard your database or
use distributed databases to handle increasing amounts of data.
3. Monitoring and Analytics: Implement robust monitoring and analytics tools to gain
insights into your application's performance. Identify areas for improvement and make data-
driven decisions.
6. Stateless Design: Design your application to be as stateless as possible. Store session data
in external systems like Redis to enable easier scaling.
7. CDN (Content Delivery Network): Use a CDN to distribute static assets closer to end-
users, reducing the load on your servers and improving response times.
Efficient Architecture:
Node.js utilizes an event-driven, non-blocking I/O model with a single-threaded event
loop, providing efficiency in handling concurrent operations.
Database Connectivity:
Node.js seamlessly connects to databases using dedicated drivers or ORM libraries,
with popular options including MongoDB, MySQL, and PostgreSQL.
1. https://nodejs.org/en/docs/
2. https://developer.mozilla.org/en-US/docs/Glossary/Node.js
3. https://docs.npmjs.com/
4. https://docs.mongodb.com/drivers/node/