A Node.js + Express RESTful API backend for a question-answer platform. Features user registration, JWT-based authentication, question and answer posting, password reset via email, and more.
The frontend is currently under development and will be available soon.
In the meantime, you can explore and test the API using Postman or any REST client.
- Node.js – Runtime environment
- Express.js – Web framework
- MongoDB & Mongoose – Database & ODM
- JWT (JSON Web Token) – Authentication system
- NodeMailer – Email handling
- dotenv – Environment variable management
- Postman – API testing
PORT=5000 NODE_ENV=development
MONGO_URI=mongodb+srv://:@.mongodb.net/?retryWrites=true&w=majority
JWT_SECRET_KEY=your_jwt_secret_key JWT_EXPIRE=10m JWT_COOKIE=10
RESET_PASSWORD_EXPIRE=3600000
SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your_email@gmail.com SMTP_PASS=your_app_specific_password
If you're using MongoDB Atlas, follow these steps:
- Create a free cluster and a database user.
- Whitelist your IP address in Atlas settings.
- Use the following URI structure:
mongodb+srv://:@.mongodb.net/?retryWrites=true&w=majority
For example:
mongodb+srv://admin:myPassword123@cluster0.abcde.mongodb.net/qa-platform?retryWrites=true&w=majority
Replace
<username>
,<password>
,<cluster>
, and<dbname>
with your actual MongoDB credentials.
Follow these steps to run the project locally:
- Clone the repository
git clone https://github.com/your-username/qa-api-backend.git cd qa-api-backend
- Install dependencies
npm install
- Configure environment variables
- Copy
env.example
toconfig/env/config.env
(see above). - Update
config.env
with your MongoDB URI, JWT secret, and SMTP credentials.
- Run the server
npm run dev
Ensure
nodemon
is installed globally (npm install -g nodemon
) or as a dev dependency.
Test endpoints using Postman or any API client.
🔗 Base URL (local): http://localhost:5000/api
Method | Endpoint | Description |
---|---|---|
POST | /auth/register |
Register a new user |
POST | /auth/login |
Login and receive JWT |
GET | /auth/logout |
Logout user |
Method | Endpoint | Description |
---|---|---|
POST | /questions |
Create new question |
GET | /questions |
Get all questions |
GET | /questions/:id |
Get single question |
DELETE | /questions/:id |
Delete a question |
Method | Endpoint | Description |
---|---|---|
POST | /questions/:id/answers |
Answer a question |
DELETE | /questions/:id/answers/delete |
Delete an answer |
Note: Protected routes require a JWT token in the
Authorization: Bearer <token>
header.
Maintained by emiryuksel. Feel free to open issues or submit pull requests.
This project is licensed under the MIT License.