Build Backend Servers Api With Node and Express
Build Backend Servers Api With Node and Express
Build Backend Servers Api With Node and Express
By
Supervisor
Asst. Lect. Hamid Abdul Rahman
A thesis submitted in partial fulfilment of the requirements for the degree of
Technical College
BSc
March 2024
Kirkuk, Iraq
Index
Number of page Subject
1 Introduction
2 History
2 Node.js
4 Advantages of NodeJS
6 Disadvantages of using Node.js
7 Create a backend API in Express JS
9 What is a Server
9 Uses of Servers
10 Server Component
11 Server Works
11 Types of Servers and Their Applications
14 Why Are Servers Always On?
15 Server Maintenance Plan
16 Server Maintenance Steps To Success
16 Common Server Problems & How To Fix Them
20 Conclusion
22 Reference
Introduction
All the APIs on the Bonita platform are developed in JAVA which is a
backend programming language, we found Node.js and Express more
convenient , in terms of learning and grasping the basics of it quickly.
Building an API is a challenging job that makes we feel that we am moving
out of comfort zone. In this project, we going to share how we built API
with Node.js and Express, We will explain the servers, their types and uses,
as well as the faults and how to maintain them.
1
History
Node.js was created by Ryan Dahl in 2009 with the goal of developing a
scalable network application, leveraging the V8 JavaScript engine. In 2010,
it introduced a package manager, npm, which quickly gained popularity
within the developer community. The collaboration with Microsoft in 2011
led to the improvement and expansion of Node.js, making it more accessible
to a wider audience.
Node.js
2
project led by Ryan Dahl, with the goal of extending JavaScript's reach
beyond the browser. Node.js is now commonly used for writing server-side
code for websites and desktop programs, thanks to its efficiency and
scalability.
Node.js is also known for its speed, thanks to its use of the V8 JavaScript
engine. Despite being single-threaded, it is highly scalable due to its ability
to offload tasks to the operating system, making it ideal for handling many
connections at once.
Advantages of NodeJS
3
1. Easy to learn:
Most developers have a good grasp of JavaScript for it being one of the most
popular programming languages.
The search engine is empowered by Node.js and it not only aids in the front-
end development but also has a great impact on the backend.
One of the key benefits offered by Nodejs is that it makes it easy for
developers to scale the application in horizontal as well as vertical
directions.
4. Full-stack JavaScript:
4
contributing to the further improvement and development of this server-
side JavaScript.
5
Disadvantages of using Node.js
4. Single-threaded nature:
6. Memory consumption:
6
lacks built-in support for scaling across multiple CPU cores.
To install Node JS, you can download it from the official website and follow
the instructions for your operating system. To install Express JS, you can
use the Node Package Manager (npm), which is a tool that comes with Node
JS and allows you to install and manage various packages and modules for
your project.
7
2- Create a project folder and a server file
To create a project folder, you can use any name you like, such as express-
api. To create a server file, you can use any name you like, such as app.js.
This file will contain the code for your backend API. To create the file, you
can use any text editor or IDE you prefer, such as Visual Studio Code,
Sublime Text, or Atom.
To start the server file, you need to import the express module and create
an instance of the express application. You also need to specify a port
number for your server to listen to.
To create a backend API, you need to have some data to work with. For this
example, we will use a simple data model for a blog post, which has the
following properties:
To create the routes and the handlers for the API, you need to use the app
object that you created earlier. The app object has methods that correspond
to the HTTP methods, such as app.get, app.post, app.put, and app.delete.
These methods take two arguments: a path and a callback function. The
path is a string that defines the URL for the route, and the callback function
is a function that handles the request and sends the response.
8
5- Test the API with a tool like Postman
To test the API, you can use a tool like Postman, which is a software that
allows you to send and receive HTTP requests and responses. You can
download Postman from official website and follow the instructions for
your operating system.
What is a Server
Uses of Servers
A client process may run on the same device. It can also connect over a
network to a server to run on a different device. Examples of servers may
include database servers, mail servers, print servers, file servers, web
servers, application servers, and game servers. Most frequently client-
server systems are implemented by the request-response communication.,
i.e., a client sends a request to the server. In this model, the server performs
some action and sends a response back to the client, typically with a result
or acknowledgement. designating a computer as server-class hardware
means that it is specialized for running servers on it. This implies that it is
more powerful and reliable than standard personal computers. However
9
large computing clusters may comprise many relatively simple, replaceable
server components.
Server Component
10
backup power supply and network interfaces, and configuration
management tools that enable automatic failover and load balancing.
Server Works
The windows server operating system from microsoft has the capability to
hear and respond to client requests. The types of client requests the server
can handle increase with additional installed roles or services. Another
illustration is when an additional application called Apache is put on top of
an operating system to handle requests from web browsers. A client sends a
request over the network whenever it needs data or functionality from a
server. The server gets this request and provides the necessary information
in response. This is the client-server networking request and response
model, commonly referred to as the call and response model.
1. Application Server
These servers host web apps (computer programs that run inside a web
11
browser) allowing users in the network to run and use them preventing the
installation of a copy on their own computers. These servers need not be
part of the World Wide Web. Their clients are computers with a web
browser.
2. Catalog Server
3. Communication Server
4. Computing Server
12
5. Database Server
These servers maintain and share any form of database over a network. A
database is an organized collection of data with predefined properties that
may be displayed in a table. Clients of these servers are spreadsheets,
accounting software, asset management software, or virtually any computer
program that consumes well-organized data, especially in large volumes.
6. Fax Server
These servers share one or more fax machines over a network which
eliminates the hassle of physical access. Any fax sender or recipient is the
client of these servers.
7. File Server
Shares files and folders, storage space to hold files and folders, or both, over
a network. Networked computers are the intended clients, even though
local programs can be clients.
8. Game Server
9. Mail Server
13
10. Print Server
These servers share one or more printers over a network which eliminates
the hassle of physical access. Their clients are computers in need of printing
something.
These servers host web pages. A web server is responsible for making the
World Wide Web possible. Each website has one or more web servers.
Their clients are computers with a web browser.
The servers are always on because they are commonly used to deliver
services that are constantly required, most servers are never turned off.
Consequently, when servers fail, they can cause network users and
companies many problems. To alleviate these issues, servers are commonly
set up to be fault tolerant.
Any computer act as a server with the right software. You may install an
FTP server program on computer and share files between other computers
over your network. But, you can make your home computer a server. you
14
have to keep some important points in your mind:
15
Server Maintenance Steps To Success
Servers are an essential part of any business, but they can be prone to a
variety of problems.
1. Power outages
Shutting down the server unexpectedly or instability with the power source
can result in data loss and downtime.
16
To solve this issue you must provide an alternative power supply, such as
an uninterruptible power supply (UPS), to keep the energy stable under any
condition. in case of power loss, the UPS will supply your server so you can
have enough time to securely shut it down.
Dust and high temperatures can interfere with the performance of servers,
leading to slowdowns or even complete failure. Also, dust building up on
your servers will make them overheat faster, which can damage internal
parts and slow down their performance. Poor air conditioning in a server
room can lead to overheating which could result in hardware failure or
other issues that could affect the performance of your server(s).
To prevent it, make sure to use a clean room, with controlled air. This will
provide your server with both ideal temperature and minimum dust
contact. plus, an air-controlled room can also prevent moisture on your
server. Humidity can lead to a short-circuit, putting not only your data at
risk but your employees’ life as well.
3. Out-dated firmware
Since not all software operating systems (OS) make automatic updates,
especially for older servers, you’ll have to set updates manually and help
your team to perform them. This will improve your security protocols and
prevent errors due to corrupted files or drives.
17
4. Cyber attacks and viruses
Cyber attacks and viruses can cause data loss, slowdowns, or even complete
shutdowns if not properly addressed in a timely manner. The best way to
protect your servers, and the business data, is by applying cybersecurity
protocols. You can either hire a cyber security service to provide your
business with high-standard protection, or you can build a security plan
internally.
Overload is a problem with servers that could result in slow page loads or
even crashes. This affects performances and causes frustration on your
team. To avoid, or fix, this issue you must use a server configuration that
best fits your business requirements and goals.
6. Hardware failure
Hard drive failures are one of the most common causes of server problems,
as they can lead to data loss or system instability if not addressed quickly
enough.
HDDs are delicate devices and prone to physical damage. However, SSDs
are not flawless and can have logical and physical losses as well. Also,
hardware such as hard drives and cables requires updates as well. And
incorrect hardware configuration can lead to poor performance or even
complete failure of a server. Regular checkups of the software and
hardware can prevent several problems with servers. Make sure to keep
regular backups off-site and choose different types of data storage devices
for your backups.
18
One more prevention for data loss due to hardware failure is to build a
server recovery plan.
7. Motherboard damages
8. Slow performance
9. Security breaches
19
As well as using a VPN helps protect against malicious actors trying to
access sensitive data stored on your servers.
Conclusion
Building backend servers and APIs with Node.js and Express.js provides a
powerful and flexible foundation for modern web applications. By following
best practices in development, testing, and security, developers can create
robust and scalable systems to meet the demands of today's dynamic digital
landscape.
Therefore, use the tips mentioned above, assess server components for
20
daily, weekly, and monthly maintenance and build an ideal server
maintenance plan. However, if you aren’t technically proficient with server
maintenance and management, you can opt for our Managed Hosting
services at Reseller Club.
On the flip side, if you own an in-house team of experts, and need a reliable
VPS Hosting solution, check out our KVM-powered SSD and HDD VPS plans
to get high performance, complete server management, and more at an
affordable price.
21
Reference
1. https://www.evernex.com/blog/common-server-issues-and-how-to-
troubleshoot-them/
2. https://blog.resellerclub.com/what-is-a-server-maintenance-plan-and-
how-do-i-implement-one/
3. https://dev.to/bilal1718/how-to-create-a-backend-api-in-express-js-
e0k
4. https://kirbtech.com/common-server-problems/
5. https://www.linkedin.com/pulse/story-behind-nodejs-how-changed-
web-development-mihir-b-9uljf?trk=public_post_main-feed-card_feed-
article-content
6. https://hyperskill.org/university/javascript/introduction-to-node
7. https://netcomp.com.au/blog/troubleshooting-hardware-failures/
8. https://www.salvagedata.com/common-server-issues/
22