This is the backend for the Story Creator app, handling user registration, login, story creation, and retrieval.
- Node.js (v16 or higher)
- MongoDB (Atlas or local instance)
- Postman or similar API testing tool
-
Clone the repository: git clone cd story-creator-backend
-
Install dependencies: npm install
- Create a .env file in the root directory: MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret
- Ensure your MongoDB instance is running and accessible.
- Start the server: npm start
- Access the server at http://localhost:8080.
-
Register a User
- POST /api/auth/register
- Body: { "username": "testuser", "email": "test@example.com", "password": "password123" }
-
Login a User
- POST /api/auth/login
- Body: json { "email": "test@example.com", "password": "password123" }
-
Get Current User Info
- GET /api/auth/me
- Headers: json { "Authorization": "Bearer YOUR_TOKEN" }
-
Create a Story
- POST /api/stories
- Headers: json { "Authorization": "Bearer YOUR_TOKEN" }
- Body: json { "title": "My First Story", "content": "This is the content of my first story." }
-
Get All Stories
- GET /api/stories
- Headers: json { "Authorization": "Bearer YOUR_TOKEN" }
-
Get a Specific Story
- GET /api/stories/:storyId
- Headers: json { "Authorization": "Bearer YOUR_TOKEN" }
- Postman: Import the API endpoints or manually test them using the provided examples.
- URL: Example to register a user: http://localhost:8080/api/auth/register
-
MongoDB Connection Issues:
- Ensure your IP address is whitelisted in MongoDB Atlas. ( somethime mogo requir static IP address)
- Double-check your MONGO_URI in the .env file.
-
JWT Authentication Issues:
- Verify the JWT_SECRET in your .env file is correct and consistent.