This guide provides a detailed step-by-step process to clone, install, configure, and run the project. It covers everything from setting up environment variables, including database URI, Cloudinary account, and Gmail app password, to running the project in development and production modes. Follow these instructions to seamlessly get your project up and running.
First, you need to clone the project repository from your version control platform (e.g., GitHub, GitLab).
Open your terminal and execute the following command:
git clone <repository-url>
Replace <repository-url>
with the actual URL of your repository.
Once the repository is cloned, navigate to the project directory:
cd project-name
Replace project-name
with the name of the directory created by the git clone
command.
Next, install all the required dependencies listed in the package.json
file. You can use either Yarn or npm:
With Yarn:
yarn install
Or with npm:
npm install
This command will install all the necessary packages.
The project includes an .env.example
file that contains example environment variables. Rename this file to .env
:
mv .env.example .env
This will create a .env
file where you will store your actual environment variables.
Since you already have a MongoDB cluster and user set up, retrieve the connection string from MongoDB Atlas:
-
Log in to MongoDB Atlas:
- Go to MongoDB Atlas and log in with your credentials.
-
Select Your Cluster:
- Once logged in, you’ll see your clusters on the dashboard. Click on the cluster you’ve already created.
-
Connect to Your Cluster:
- On the cluster page, click the "Connect" button.
-
Choose a Connection Method:
- Select "Connect your application."
-
Select Driver and Version:
- Ensure the "Driver" dropdown is set to "Node.js" and the version is appropriate.
-
Copy the Connection String:
- MongoDB Atlas will display a connection string like this:
mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/<dbname>?retryWrites=true&w=majority
-
Replace Placeholders in the Connection String:
- Replace
<username>
with your MongoDB username. - Replace
<password>
with your MongoDB user's password. - Replace
<dbname>
with the name of the database you want to connect to.
For example:
mongodb+srv://admin:[email protected]/lost-and-found?retryWrites=true&w=majority
- Replace
-
Add the Database URI to Your
.env
FileOpen the
.env
file in the project root and add the following line:DB_URL=mongodb+srv://admin:[email protected]/lost-and-found?retryWrites=true&w=majority
Replace the URI with your actual MongoDB connection string.
Cloudinary is used for managing and delivering images. To set it up:
- Visit Cloudinary.
- Sign up or log in to your account.
- Go to the Cloudinary Dashboard.
- Note down your
Cloud Name
,API Key
, andAPI Secret
.
Add these credentials to your .env
file:
CLOUDINARY_CLOUD_NAME=<your-cloud-name>
CLOUDINARY_API_KEY=<your-api-key>
CLOUDINARY_API_SECRET=<your-api-secret>
Replace <your-cloud-name>
, <your-api-key>
, and <your-api-secret>
with your Cloudinary account details.
To send emails through your Gmail account, you need to generate an app password:
- Go to your Google Account Security Settings.
- Under "Signing in to Google," enable 2-Step Verification.
- Once 2-Step Verification is enabled, go back to the Security page and click on "App passwords."
- Select "Mail" as the app and your device type, then generate the app password.
- Copy the generated password.
Add your Gmail credentials to the .env
file:
SENDER_EMAIL=<your-email>
SENDER_APP_PASS=<your-app-password>
Replace <your-email>
with your Gmail address and <your-app-password>
with the app password you generated.
Complete your .env
file with the following variables:
NODE_ENV=development
PORT=3000
BCRYPT_SALT_ROUNDS=12
JWT_ACCESS_SECRET=secret
JWT_ACCESS_EXPIRES_IN=7d
JWT_REFRESH_SECRET=refreshsecret
JWT_REFRESH_EXPIRES_IN=1y
[email protected]
ADMIN_PASSWORD=123456
ADMIN_MOBILE_NUMBER=1234567890
ADMIN_PROFILE_PHOTO=https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png
After setting up the environment variables, you can run the project.
To start the project in development mode, run:
With Yarn:
yarn dev
Or with npm:
npm run dev
This will start the development server with hot-reloading enabled.
To start the project in production mode:
-
Build the Project:
With Yarn:
yarn build
Or with npm:
npm run build
-
Start the Server:
With Yarn:
yarn start
Or with npm:
npm start
Once the server is running, you can access the application in your browser by visiting:
http://localhost:5000
This guide should help you set up, configure, and run your project seamlessly. If you encounter any issues or need further assistance, feel free to ask!