# Smartwatch-Based Monitoring and Alert System for Factory Operators Using Public Cloud Services
## 3 Materials and Methods
### The Implementation of the Proposed Solution
#### 3.2.5 Implementing the Server Application  
The application server of the system, which handles requests from both the web application and the mobile application for smartwatches, was implemented using Node.js, along with the Express framework.  
The server is executed by running the \"server.js\" file, which handles its initialization and configuration. Within this file, all the system routes are found, i.e., all access points to the server are defined, each with a specific role in the system's operation. Thus, the routes configure different entry points for operations related to authentication, employee management, supervision, tasks, and notifications. Each module handles different aspects of interactions within the applications, providing a clear and well-organized structure for manipulating and processing the data received in incoming requests.  
The server contains six routes, each with a specific purpose and a series of HTTP methods structured according to REST principles, used to serve requests from both the web and mobile applications. Below, all routes are described along with their methods. Subsequently, in the presentations of the other modules, reference will be made to the routes described in this section that handle requests from clients, without adding implementation details.  
In the Express framework, a route consists of an HTTP verb, such as POST, GET, PUT, DELETE, a URL path, and a function that is called when a request is honored to the respective endpoint. To use them, a Router object is created, which allows defininga group of routes under a common path. The routes are added to this object, and then it is exported to be used. By applying the use() method to the server initialized by Express, the exported Router object is added to the middleware chain by specifying the URL path on which the route will handle requests. The middleware chain represents a series of functions, which are executed in the order in which they are defined in the application code, to process requests and responses before reaching the final route logic or responding to the client. Thus, middleware is a function that has access to the request object (req), the response object (res), and the next middleware function in the request-response cycle of the application, often called next.  
To utilize Firebase Cloud Messaging, we had to establish a connection between the server and Firebase services within the server and set up the necessary functionalities to interact with FCM. This allowed us to send push notifications from the server to user devices.  
After downloading the private key associated with the project created in Firebase, we configured the server's authentication method with Firebase and accessed the functionalities of the Firebase Admin SDK, which enables interaction with Firebase services. Subsequently, we established a secure connection between the Node.js server and Firebase by providing credentials and configured an instance of the messaging service, which we later exported.  
Therefore, the exported messaging service is used in another application file that defines endpoints for the \"/api/notifications\" route to send push notifications to users, using methods such as send, sendMulticast, to manage communication between the server and the client. In short, the server is responsible for receiving requests to send notifications between devices and honoring them according to the situation encountered.