|
1 | 1 | # JavaScript Express.js MongoDB Sample MFlix Application |
2 | 2 |
|
3 | | -[TODO: Add intro] |
| 3 | +This is a full-stack movie browsing application built with Express.js and Next.js, demonstrating MongoDB operations using the `sample_mflix` dataset. The application showcases CRUD operations, aggregations, and MongoDB Search using the native MongoDB Node.js driver. |
| 4 | + |
| 5 | +## Project Structure |
4 | 6 |
|
5 | 7 | ``` |
6 | 8 | ├── README.md |
7 | | -├── client/ # Next.js frontend |
8 | | -└── server/ # Express.js backend |
| 9 | +├── client/ # Next.js frontend (TypeScript) |
| 10 | +└── server # Express.js backend |
| 11 | + ├── src/ |
| 12 | + ├── package.json |
| 13 | + ├── .env.example |
| 14 | + └── tsconfig.json |
9 | 15 | ``` |
10 | 16 |
|
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +- **Node.js 22** or higher |
| 20 | +- **MongoDB Atlas cluster or local deployment** with the `sample_mflix` dataset loaded |
| 21 | + - [Load sample data](https://www.mongodb.com/docs/atlas/sample-data/) |
| 22 | +- **npm** (included with Node.js) |
| 23 | +- **Voyage AI API key** (For MongoDB Vector Search) |
| 24 | + - [Get a Voyage AI API key](https://www.voyageai.com/) |
| 25 | + |
11 | 26 | ## Getting Started |
12 | 27 |
|
13 | | -[TODO: Add getting started instructions explaining how to set connection string, start server, start client, etc.] |
| 28 | +### 1. Configure the Backend |
| 29 | + |
| 30 | +Navigate to the Express server directory: |
| 31 | + |
| 32 | +```bash |
| 33 | +cd server |
| 34 | +``` |
| 35 | + |
| 36 | +Create a `.env` file from the example: |
| 37 | + |
| 38 | +```bash |
| 39 | +cp .env.example .env |
| 40 | +``` |
| 41 | + |
| 42 | +Edit the `.env` file and set your MongoDB connection string: |
| 43 | + |
| 44 | +```env |
| 45 | +# MongoDB Connection |
| 46 | +# Replace with your MongoDB Atlas connection string or local MongoDB URI |
| 47 | +MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/sample_mflix?retryWrites=true&w=majority |
| 48 | +
|
| 49 | +# Voyage AI Configuration |
| 50 | +# API key for Voyage AI embedding model (required for Vector Search) |
| 51 | +VOYAGE_API_KEY=your_voyage_api_key |
| 52 | +
|
| 53 | +# Server Configuration |
| 54 | +PORT=3001 |
| 55 | +NODE_ENV=development |
| 56 | +
|
| 57 | +
|
| 58 | +# CORS Configuration |
| 59 | +# Allowed origin for cross-origin requests (frontend URL) |
| 60 | +# For multiple origins, separate with commas |
| 61 | +CORS_ORIGIN=http://localhost:3000 |
| 62 | +
|
| 63 | +# Optional: Enable MongoDB Search tests |
| 64 | +# Uncomment the following line to enable Search tests |
| 65 | +# ENABLE_SEARCH_TESTS=true |
| 66 | +``` |
| 67 | + |
| 68 | +**Note:** Replace `<username>`, `<password>`, and `<cluster>` with |
| 69 | +your actual MongoDB Atlas credentials. Replace `your_voyage_api_key` with |
| 70 | +your key. |
| 71 | + |
| 72 | +### 2. Install Backend Dependencies |
| 73 | + |
| 74 | +From the `server` directory, run: |
| 75 | + |
| 76 | +```bash |
| 77 | +npm install |
| 78 | +``` |
| 79 | + |
| 80 | +### 3. Start the Backend Server |
| 81 | + |
| 82 | +From the `server` directory, run: |
| 83 | + |
| 84 | +```bash |
| 85 | +# Development mode with hot reloading |
| 86 | +npm run dev |
| 87 | +``` |
| 88 | + |
| 89 | + |
| 90 | +Or for production mode, run: |
| 91 | + |
| 92 | +```bash |
| 93 | +npm run build |
| 94 | +npm start |
| 95 | +``` |
| 96 | + |
| 97 | +The server will start on `http://localhost:3001`. You can verify it's running by visiting: |
| 98 | +- API root: http://localhost:3001/ |
| 99 | +- API documentation (Swagger UI): http://localhost:3001/api-docs |
| 100 | + |
| 101 | +### 4. Configure and Start the Frontend |
| 102 | + |
| 103 | +Open a new terminal and navigate to the client directory: |
| 104 | + |
| 105 | +```bash |
| 106 | +cd client |
| 107 | +``` |
| 108 | + |
| 109 | +Install dependencies: |
| 110 | + |
| 111 | +```bash |
| 112 | +npm install |
| 113 | +``` |
| 114 | + |
| 115 | +Start the development server: |
| 116 | + |
| 117 | +```bash |
| 118 | +npm run dev |
| 119 | +``` |
| 120 | + |
| 121 | +The Next.js application will start on `http://localhost:3000`. |
| 122 | + |
| 123 | +### 5. Access the Application |
| 124 | + |
| 125 | +Open your browser and navigate to: |
| 126 | +- **Frontend:** http://localhost:3000 |
| 127 | +- **Backend API:** http://localhost:3001 |
| 128 | +- **API Documentation:** http://localhost:3001/api-docs |
| 129 | + |
| 130 | +## Features |
| 131 | + |
| 132 | +- **Browse Movies:** View a paginated list of movies from the |
| 133 | + sample_mflix dataset |
| 134 | +- **CRUD Operations:** Create, read, update and delete movies by using |
| 135 | + the MongoDB Node.js driver |
| 136 | +- **Search:** Search movies with filters by using MongoDB Search |
| 137 | +- **Vector Search:** Search movie plots with similar search terms by |
| 138 | + using MongoDB Vector Search |
| 139 | +- **Aggregations:** View data aggregations and analytics built with |
| 140 | + aggregation pipelines |
| 141 | + |
| 142 | +## Development |
| 143 | + |
| 144 | +### Backend Development |
| 145 | + |
| 146 | +The Express.js backend uses: |
| 147 | +- **Express.js 5** for REST API |
| 148 | +- **MongoDB Node.js Driver** for database operations |
| 149 | +- **TypeScript** for type safety |
| 150 | +- **Swagger** for API documentation |
| 151 | +- **Jest** for testing |
| 152 | + |
| 153 | +To run tests: |
| 154 | + |
| 155 | +```bash |
| 156 | +cd server |
| 157 | +npm test |
| 158 | +``` |
| 159 | + |
| 160 | +To run tests with coverage: |
| 161 | + |
| 162 | +```bash |
| 163 | +cd server |
| 164 | +npm run test:coverage |
| 165 | +``` |
| 166 | + |
| 167 | +### Frontend Development |
| 168 | + |
| 169 | +The Next.js frontend uses: |
| 170 | +- **React 19** with TypeScript |
| 171 | +- **Next.js 16** with App Router |
| 172 | +- **Turbopack** for fast development builds |
| 173 | + |
| 174 | +#### Development Mode |
| 175 | + |
| 176 | +For active development with hot reloading and fast refresh: |
| 177 | + |
| 178 | +```bash |
| 179 | +cd client |
| 180 | +npm run dev |
| 181 | +``` |
| 182 | + |
| 183 | +This starts the development server on `http://localhost:3000` with Turbopack for fast rebuilds. |
| 184 | + |
| 185 | +#### Production Build |
| 186 | + |
| 187 | +To create an optimized production build and run it: |
| 188 | + |
| 189 | +```bash |
| 190 | +cd client |
| 191 | +npm run build # Creates optimized production build |
| 192 | +npm start # Starts production server |
| 193 | +``` |
| 194 | + |
| 195 | +The production build: |
| 196 | +- Minifies and optimizes JavaScript and CSS |
| 197 | +- Optimizes images and assets |
| 198 | +- Generates static pages where possible |
| 199 | +- Provides better performance for end users |
| 200 | + |
| 201 | +#### Linting |
| 202 | + |
| 203 | +To check code quality: |
| 204 | + |
| 205 | +```bash |
| 206 | +cd client |
| 207 | +npm run lint |
| 208 | +``` |
14 | 209 |
|
15 | 210 | ## Issues |
16 | 211 |
|
|
0 commit comments