This is a simple chatroom application built with Node.js and Express that allows users to register, log in, and send, edit, and delete messages. The application uses Sequelize for database interactions and cookies to manage user sessions.
- Login: Users can log in with their email and password.
- Registration: New users can register by entering their email, first name, last name, and setting a password.
- Message System: Users can send, edit, and delete messages in the chatroom.
- Search: Users can search messages by keywords.
- Session Management: Users are logged in with a cookie that expires after 30 seconds for security reasons.
- Error Handling: The application provides error messages for invalid inputs or actions.
- Node.js: Version 14 or higher
- npm: Node package manager for dependencies
- Sequelize: ORM for managing the database
- Express: Web framework for handling routes and HTTP requests
- Cookie-Parser: Middleware for cookie management
-
Clone this repository:
git clone <repository-url> cd chatroom
-
Install dependencies:
npm install
-
Run the application:
npm start
The application will run on
http://localhost:3000
.
- Login Page: Navigate to
/
to log in. Use your email and password to sign in. - Register Page: If you don't have an account, you can register at
/register
. - Chatroom: After logging in, you will be redirected to the
/chatroom
page where you can send, edit, and delete messages. - Search: You can search for messages using the
/chatroom/search?term=<keyword>
endpoint. - Logout: You can log out by visiting the
/logout
route.
- GET /: Displays the login page.
- POST /login: Authenticates a user.
- GET /logout: Logs out the user.
- GET /register: Displays the registration form.
- POST /register: Handles user registration (step 1).
- GET /register/password: Displays the password input page.
- POST /register/password: Handles password input and registration (step 2).
- GET /chatroom: Displays the chatroom if the user is logged in.
- GET /chatroom/messages: Retrieves all messages in the chatroom.
- POST /chatroom/send: Sends a new message.
- DELETE /chatroom/delete/:id: Deletes a message by ID.
- PUT /chatroom/edit/:id: Edits a message by ID.
- GET /chatroom/search: Searches for messages by keyword.
The application uses various checks for error handling, such as:
- Invalid login credentials
- Invalid or expired registration cookie
- Invalid input data (e.g., incorrect email format, passwords not matching)
- Server errors when accessing or modifying messages
- Node.js
- Express for routing
- Sequelize for ORM and database management
- EJS for templating
- Cookies for session management
- Samah Rajabi