The Mango Messenger project is a messaging application that allows users to create accounts, log in, send messages, and view their messages. The project consists of both client-side and server-side code.
Client-Side: The client-side code includes HTML, CSS, and JavaScript that create the user interface for the messaging application.
-
Account Creation: The account creation page allows users to create an account by providing their full name, username, password, and confirming the password. The client-side JavaScript code validates the form input and sends a POST request to the server to create the account.
-
Login: The login page provides a form where users can enter their username and password to log into their Mango Messenger account. The client-side JavaScript code sends a POST request to the server with the login credentials and displays an alert indicating the success or failure of the login attempt.
-
Sending Messages/Viewing Messages: The content page allows users to send messages to other users and view their own messages. The user can enter the sender's username, recipient's username, and the message text in a form. The JavaScript code sends a POST request to the server to send the message and updates the message display area with the received messages. The page also includes a sign-out button to log out the user.
Server-Side: The server-side code is implemented using Node.js, Express.js, and PostgreSQL to handle the backend functionality of the messaging application.
-
Dependencies: The server-side code requires several dependencies, including Express.js, CORS, body-parser, pg, and Pool, to handle routing, middleware, and database interactions.
-
Express Application: An Express application is created, and the necessary middleware for handling request bodies and enabling CORS is set up.
-
PostgreSQL Connection Pool: A PostgreSQL connection pool is created to establish a connection with the PostgreSQL database.
-
Account Creation: A route is defined to handle the creation of user accounts. It receives a POST request with user details, validates the input, and inserts the user data into the PostgreSQL database.
-
Login: A route is defined to handle user login. It receives a POST request with login credentials, checks the credentials against the database, and responds with the result.
-
Sending a Message: A route is defined to handle sending messages. It receives a POST request with the sender's username, recipient's username, and message text. It validates the recipient's username and inserts the message data into the PostgreSQL database.
-
Fetching User Messages: A route is defined to fetch user messages. It receives a GET request with the recipient's username as a query parameter and retrieves the corresponding messages from the PostgreSQL database.
-
Server Initialization: The server is started and listens on port 3000.
The combination of the client-side and server-side code enables users to create accounts, log in, send messages, and view their messages within the Mango Messenger application.