this is a nodejs application for the backend of the netflix application which is built with reactjs and this is the backend for it.
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT (JSON Web Tokens)
- bcryptjs
- Joi
- Clone the repository.
- Install the required dependencies using the command
npm install
. - Set up the environment variables by creating a
.env
file and filling in the necessary information (e.g., PORT MONGO_URI JWT_SECRET AUTH_MAX_AGE ). - Run the application using the command
npm start
.
in this application you can do the following:
-
signUp : This function handles the user sign-up process. It takes the user's information (firstName, lastName, email, password, profilePicture) from the request body, checks if the user already exists, hashes the password, creates a new user in the database, generates a JWT token, sets the token as a cookie, and returns the user's information along with the token.
-
signIn : This function handles the user sign-in process. It takes the user's email and password from the request body, checks if the user exists in the database, compares the passwords, generates a JWT token, sets the token as a cookie, and returns the user's information along with the token.
-
signOut : This function handles the user sign-out process. It clears the token cookie and returns a success message.
The file also imports necessary dependencies and helper functions from other files, such as bcrypt for password hashing and User model for interacting with the database. It uses the JWT configuration for generating and handling tokens. The AUTH_MAX_AGE environment variable is used to set the maximum age of the token cookie.
-
getAllUsers : Retrieves a paginated list of all users from the database, excluding the password field. Returns the list of users in the response.
-
getUserById : Retrieves a specific user by their ID from the database, excluding the password field. Returns the user object in the response.
-
getOwnData : Retrieves the data of the currently authenticated user by their ID from the database, excluding the password field. Returns the user object in the response. This function also checks if the authenticated user ID matches the requested user ID, ensuring authorization.
-
createUser : Validates the request body using a Joi schema and creates a new user in the database with the provided information. Returns the created user object in the response.
-
updateUser : Validates the request body using a Joi schema and updates an existing user in the database with the provided information. If a new password is provided, it is hashed before updating. Returns the updated user object in the response.
-
updateUserRole : Updates the role of an existing user in the database. Validates that the new role is either "admin" or "user". Returns the updated user object in the response.
-
deleteUser : Deletes a user from the database based on their ID. Returns the deleted user object in the response.
-
getAllMovies : Retrieves a paginated list of all movies from the database. Returns the list of movies in the response.
-
getRandomMovie : Retrieves a random movie from the database. Returns the movie object in the response.
-
getMovieById : Retrieves a specific movie by its ID from the database. Returns the movie object in the response.
-
createMovie : Validates the request body using a Joi schema and creates a new movie in the database with the provided information. Returns the created movie object in the response.
-
updateMovie : Validates the request body using a Joi schema and updates an existing movie in the database with the provided information. Returns the updated movie object in the response.
-
deleteMovie : Deletes a movie from the database based on its ID. Returns the deleted movie object in the response.
-
searchMovies : Performs a search for movies based on the provided query parameters (seriesTitle, releasedYear, genres). Returns a list of movies that match the search criteria in the response.
/api/auth
- Authentication routes./api/users
- User routes./api/movies
- Movie routes.
Provide a brief description of each route and its purpose.
Explain how errors are handled in your application. Mention any specific middleware or techniques used for error handling.
If you would like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your forked repository.
- Submit a pull request describing your changes.