movie_api

Movie API

A comprehensive RESTful API for managing movies and users, built with Node.js, Express, and MongoDB. This backend service provides JWT-based authentication, user management, and movie database operations with complete JSDoc documentation.


Table of Contents


Features


Prerequisites


Setup

  1. Clone the repository
git clone https://github.com/CreativeMarkus/movie_api.git
cd movie_api
  1. Install dependencies
npm install
  1. Create environment file

Create a .env file in the root directory:

cp .env.example .env  # If example exists, or create manually
  1. Configure environment variables

Edit .env with your MongoDB connection string and JWT secret:

MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
PORT=8080

Environment Variables

Variable Description Required Default
MONGODB_URI MongoDB connection string Yes -
JWT_SECRET Secret key for JWT token signing Yes your_jwt_secret
PORT Server port No 8080

Running the Server

Development Mode

npm run dev  # Uses nodemon for auto-restart

Production Mode

npm start    # Standard node server

The server will start on http://localhost:8080 (or your specified PORT).


Documentation

This project includes comprehensive JSDoc documentation for all API endpoints, models, and modules.

Viewing Documentation

Option 1: Generate and Open

npm run docs:open  # Generates docs and opens in browser

Option 2: Generate Only

npm run docs       # Generates documentation in docs/ folder

Option 3: Manual

jsdoc -c jsdoc.conf.json  # Using JSDoc directly

The generated documentation includes:

Documentation Files


API Endpoints

Authentication

Users

Movies

Directors

Genres

Static Files

Documentation


Authentication

This API uses JWT (JSON Web Tokens) for authentication. Most endpoints require a valid JWT token.

Getting a Token

  1. Register a new user: POST /users
  2. Login with credentials: POST /login
  3. Use the returned token in subsequent requests

Using the Token

Include the JWT token in the Authorization header:

Authorization: Bearer <your_jwt_token>

Example Login Request

curl -X POST http://localhost:8080/login \
  -H "Content-Type: application/json" \
  -d '{
    "Username": "testuser",
    "Password": "password123"
  }'

Project Structure

movie_api/
├── docs/                  # Generated JSDoc documentation
├── models/                # Mongoose schemas
│   ├── movies.js          # Movie model
│   ├── users.js           # User model
│   ├── directors.js       # Director model
│   └── genres.js          # Genre model
├── routes/                # Express route handlers
│   ├── movies.js          # Movie routes
│   ├── users.js           # User routes
│   ├── directors.js       # Director routes
│   └── genres.js          # Genre routes
├── public/                # Static files
│   ├── index.html         # Home page
│   └── documentation.html # API documentation
├── logs/                  # Log files
├── auth.js                # Authentication logic
├── passport.js            # Passport strategies
├── server.js              # Main server file
├── models.js              # Centralized models export
├── jsdoc.conf.json        # JSDoc configuration
├── API_README.md          # Additional API documentation
├── package.json           # Dependencies and scripts
├── .env                   # Environment variables
├── Procfile               # Heroku deployment config
└── README.md              # Project documentation

├── models.js # Centralized models export ├── package.json # Dependencies and scripts ├── .env # Environment variables ├── Procfile # Heroku deployment config └── README.md # Project documentation


---

## Technologies Used

- **Backend Framework**: Express.js
- **Database**: MongoDB with Mongoose ODM
- **Authentication**: Passport.js with JWT strategy
- **Password Hashing**: bcrypt
- **HTTP Logging**: Morgan
- **CORS**: cors middleware
- **Environment Variables**: dotenv
- **Development**: nodemon for auto-restart
- **Documentation**: JSDoc with comprehensive API documentation
- **Code Comments**: Extensive inline and block comments throughout

---

## Deployment

### Heroku
This app is configured for Heroku deployment with the included `Procfile`.

1. **Create Heroku app**
```bash
heroku create your-app-name
  1. Set environment variables
    heroku config:set MONGODB_URI=your_mongodb_uri
    heroku config:set JWT_SECRET=your_jwt_secret
    
  2. Deploy
    git push heroku main
    

Other Platforms

The app can be deployed on any Node.js hosting platform. Ensure environment variables are properly configured.


Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the ISC License. See the LICENSE file for details.


Author

CreativeMarkus - GitHub Profile


Support

If you encounter any issues or have questions, please open an issue on GitHub.