A simplified web application that replicates core functionalities of Stack Overflow. This project is built using Node.js and MongoDB, with a front end styled using Tailwind CSS.
- User authentication with JWT
- Question and answer management
- Basic user profiles with personal asked questions and answer given
- User can ask questions, answer questions, delete their own questions and answers
- List all questions and view details of each question
- Tailwind CSS for styling
- Frontend: EJS, Tailwind CSS
- Backend: Node.js, Express.js, Mongoose
- Database: MongoDB(using compass)
- Clone the repository:
git clone https://github.com/sksmagr23/CodeExchange.git cd CodeExchange
- Install dependencies:
npm install
- Create a .env file in root directory and set up environment variables:
MONGO_URL=your_mongodb_connection_string JWT_SECRET=your_jwt_secret
- Start the server:
npm start // The server should now be running at 'http://localhost:3000'
- Register User:
- POST /api/auth/register
- Request Body:
{ "username": "yourusername", "email": "[email protected]", "password": "yourpassword" }
- Response:
{ "token": "your_jwt_token" }
- Login User:
- POST /api/auth/login
- Request Body:
{ "email": "[email protected]", "password": "yourpassword" }
- Response:
{ "token": "your_jwt_token" }
- Logout User:
- GET /api/auth/logout
- Response:
{ "message":"Logged out successfully" }
- Get User Profile:
- GET /profile
- Headers:
{ "Authorization":"Bearer your_jwt_token" }
- Response:
{ "username": "yourusername", "email": "[email protected]", "questions": [...], "answers": [...] }
- Get All Questions:
- GET /questions
- Response:
[ { "_id": "question_id", "title": "Question Title", "description": "Question Description", "user": { "username": "username" }, "createdAt": "date_string" }, ... ]
- Get Questions By ID:
- GET /questions/:id
- Response:
{ "_id": "question_id", "title": "Question Title", "description": "Question Description", "user": { "username": "username" }, "createdAt": "date_string", "answers": [ { "_id": "answer_id", "text": "Answer Text", "user": { "username": "username" }, "createdAt": "date_string" }, ... ] }
- Create Question:
- POST /questions
- Headers:
{ "Authorization":"Bearer your_jwt_token" }
- Request Body:
{ "title": "Question Title", "description": "Question Description" }
- Response:
{ "_id": "question_id", "title": "Question Title", "description": "Question Description", "user": "user_id", "createdAt": "date_string" }
- Delete Question:
- DELETE /questions/:id
- Headers:
{ "Authorization":"Bearer your_jwt_token" }
- Response:
{ "message":"Question deleted" }
- Create Answer
- POST /questions/:id/answers
- Headers:
{ "Authorization":"Bearer your_jwt_token" }
- Request Body:
{ "text":"Answer Text" }
- Response:
{ "_id": "answer_id", "text": "Answer Text", "user": "user_id", "question": "question_id", "createdAt": "date_string" }