This is a simple backend project that uses the TMDB API to search movies, get trending movies, and get movie details.
The project is written in pure JavaScript and uses the Node.js built-in HTTP server
- Search movies by name
- Show trending movies
- Show details of one movie by movie id
- Return JSON responses from HTTP routes
- Keep the code in a clean beginner-friendly folder structure
Create a file named .env in the main project folder:
TMDB_API_KEY=your_real_tmdb_api_key_here
PORT=3000You can also copy .env.example and rename the copy to .env.
Important: never upload your .env file to GitHub. It contains your private API key.
Install packages:
npm installStart the backend:
npm startThe server will run here:
http://localhost:3000Check if the backend is running:
GET /healthSearch movies:
GET /movies/search?query=batmanGet trending movies:
GET /movies/trendingGet one movie by id:
GET /movies/550Example browser URL:
http://localhost:3000/movies/search?query=batmansrc/
|
|-- app/
| |-- server.js
| |-- routes.js
| `-- middleware/
|
|-- modules/
| |
| |-- movies/
| | |-- domain/
| | | |-- Movie.js
| | | `-- MovieRepository.js
| | |
| | |-- application/
| | | |-- SearchMovies.js
| | | |-- GetMovieDetails.js
| | | `-- GetTrendingMovies.js
| | |
| | |-- infrastructure/
| | | |-- TmdbMovieRepository.js
| | | `-- movie.mapper.js
| | |
| | `-- presentation/
| | |-- movie.controller.js
| | `-- movie.routes.js
| |
| |-- tv/
| |-- people/
| |-- auth/
| `-- favorites/
|
|-- shared/
| |-- http/
| |-- logger/
| |-- cache/
| |-- config/
| |-- errors/
| `-- utils/
|
|-- database/
| |-- prisma/
| `-- migrations/
|
|-- tests/
| |-- integration/
| `-- unit/
|
`-- index.jsRoute: a URL path that does something. Example: /movies/trending.
Controller: the file that receives a request and decides what response to send.
Module: a folder for one feature. In this project, movies is a module.
Domain: the core business rules and types. It should not care about HTTP or TMDB details.
Application: the use cases of the app. Example: SearchMovies.
Infrastructure: code that talks to outside things, like the TMDB API or a database.
Repository: a class or interface used to get data. Here, MovieRepository says what movie data methods must exist.
Mapper: code that changes data from one shape to another. TMDB data is converted into our own Movie shape.
Shared: code that can be used by many modules, like config, errors, logging, and HTTP helpers.
Environment variable: a value stored outside the code. Your API key is stored in .env as TMDB_API_KEY.
JavaScript: the programming language used in this project.
Node.js: the program that lets JavaScript run outside the browser.
When you visit:
/movies/search?query=batmanThe request goes through this path:
index.js
app/server.js
app/routes.js
movie.routes.js
movie.controller.js
SearchMovies.js
TmdbMovieRepository.js
TMDB APIThen the backend sends JSON back to the browser or API client.
- some folder are just empty , are made for structural reasons only
- The
tv,people,auth, andfavoritesfolders are placeholders for future features - readme is ai generated , so will definetly update it in the future