This repository contains a Node.js project for handling authentication, conversations, and messages. The project includes API endpoints for user authentication, managing conversations, and message operations.
Ensure you have Node.js and npm (Node Package Manager) installed on your system. You can download and install them from Node.js official website.
Clone the repository and install the dependencies:
git clone https://yourrepositoryurl.git
cd node-test
npm install
Copy the .env.example
file to create a .env
file and update it with your local settings:
cp NODE_ENV=local
PORT=3001
MYSQL_DB_HOST=localhost
MYSQL_DB_USERNAME=root
MYSQL_DB_PASSWORD=
MYSQL_DB_NAME=
TOKEN_EXPIRATION_TIME=30
TOKEN_EXPIRATION_TIME_REMEMBER_ME=300
To set up your database schema, run the migrations:
npm run migrate
To populate your database with initial data, run the seeders:
npm run seed
Start the server with:
npm run dev
The application supports various operations through its API endpoints grouped into categories:
-
POST
/api/auth/login
- Authenticate a user:{ "email": "[email protected]", "password": "testing1234!" }
-
POST
/api/auth/logout
- Log out the current user.- Requires token authentication.
-
POST
/api/auth/verify-code
- Verify a user's authentication code:{ "email": "[email protected]", "verificationCode": "563256" }
-
GET
/api/conversation/
- Retrieve all conversations.- Query parameters:
keyword
(optional), requires token.
- Query parameters:
-
POST
/api/conversation/
- Create a new conversation:{ "userId": 2 }
- Requires token authentication.
-
GET
/api/message/
- Retrieve messages for a conversation.- Query parameters:
conversationId
, requires token.
- Query parameters:
-
POST
/api/message/
- Post a new message:{ "conversationId": 1, "content": "i am deleting this messsage" }
- Requires token authentication.
-
DELETE
/api/message/:id
- Delete a message:- Query parameter:
deleteWith
(options: "everyone" or "me"). - Requires token authentication.
- Query parameter:
This project uses the following tools and libraries:
- Express: Web application framework for Node.js.
- Sequelize: ORM for Node.js.
- Sentry: Error tracking and monitoring.
- Socket.IO: For real-time bidirectional event-based communication.
- express-rate-limit: Middleware for rate-limiting incoming requests.