This guide will walk you through setting up a Node.js project with MongoDB and configuring environment variables for database connection and email credentials.
-
Clone the project repository from GitHub:
git clone https://github.com/saaya-code/carbon-footprint-explorer.git
-
Navigate into the project directory:
cd carbon-footprint-explorer/
- Install Node.js dependencies using npm:
npm install
-
Install MongoDB Community Edition
- Visit the MongoDB Download Center and download the Community Server version suitable for your operating system.
- Follow the installation instructions for your OS.
-
Start MongoDB Server
- After installation, start the MongoDB server:
- On Windows, use the Command Prompt or PowerShell and run
mongod. - On macOS/Linux, open a terminal and run
mongod.
- On Windows, use the Command Prompt or PowerShell and run
- MongoDB server should now be running on
localhost:27017by default.
- After installation, start the MongoDB server:
-
Create a Database and Collection
- You can create a database and collection using MongoDB Compass or through the MongoDB shell (
mongocommand). - Example using MongoDB shell:
# Connect to MongoDB mongo # Create a new database use carbonFootprint
- You can create a database and collection using MongoDB Compass or through the MongoDB shell (
-
Create
.envFile- In the root of your Node.js project, create a
.envfile if it doesn't already exist.
- In the root of your Node.js project, create a
-
Environment Variables
-
Add the following environment variables to your
.envfile:# MongoDB Connection URI MONGODB_URI=mongodb://localhost:27017/carbonFootprint # Example Email Credentials (replace `<your mail>` and `<your password>` with your actual email credentials) EMAIL_USER=<your mail> EMAIL_PASS=<your password>
-
Replace
carbonFootprintinMONGODB_URIwith the name of your MongoDB database. -
Replace
<your mail>and<your password>with your actual email credentials for sending confirmation emails.
-
-
Run the application in dev mode:
npm run dev
-
Access the application in your web browser at
http://localhost:3000. -
Run the application in production mode:
npm run build npm start