Before proceeding, ensure that you have the following:
- A Google account to access Firebase services.
- Node.js installed on your machine.
- A text editor (e.g., VSCode) to edit environment variables and project files.
- Go to Firebase and sign in with your Google account.
- Click on Get Started to create your first Firebase project.
- Click on Add Project and enter
next-ecommerce
as the project name. - Click Continue, disable Google Analytics.
- Click Create Project.
- Wait for the project to be created, then click Continue.
- In your Firebase dashboard, select your newly created
next-ecommerce
project. - In the left-hand menu, click Build and then select Firestore Database.
- Click Create Database, choose Start in test mode, and click Create.
- In the Firebase console, go to the Project Overview (the gear icon in the top-left corner).
- Click on the </> Web icon to create a new Firebase Web App.
- Enter an app nickname (e.g.,
next-ecommerce-app
), and click Register app. - Firebase will display the Firebase configuration. Copy this configuration as you will need it later.
- Click Continue to Console.
-
Clone this repo and run
npm install
to install dependencies -
Create a .env file in the root of your project and add the following to the file:
FIREBASE_API_KEY=your_api_key FIREBASE_AUTH_DOMAIN=your_auth_domain FIREBASE_PROJECT_ID=your_project_id FIREBASE_STORAGE_BUCKET=your_storage_bucket FIREBASE_MESSAGING_SENDER_ID=your_messaging_sender_id FIREBASE_APP_ID=your_app_id
-
After registering your web app in Firebase, you will see the Firebase SDK configuration displayed on the Firebase Console. Click on Project Overview, just below your project name (on the main screen) you will 1 app which is the web app registered in step 3.
-
Click on 1 app icon, then click the settings gear next to the registered app name, scrol down and you will see your SDK config - make sure to select npm
-
Copy your key values without quotation marks and replace the values in your .env file with the actual keys
FIREBASE_API_KEY=XYZDFOEKEONINPN
FIREBASE_AUTH_DOMAIN=next-ecommerce-lkjoip9.dfeofke
FIREBASE_PROJECT_ID=next-ecommerce-lkjoip9
FIREBASE_STORAGE_BUCKET=next-ecommerce-lkjoip9.kojnpn
FIREBASE_MESSAGING_SENDER_ID=26661115351514145
FIREBASE_APP_ID=1:5444:eekohrgjrgoirngu
To upload the provided products and categories data to Firestore:
- Ensure that your Firebase environment variables are set correctly in your .env file.
- Run the following command in your terminal:
node uploadData.js
This script will upload your product and category data to Firestore, using padded IDs for products and storing all categories under a single document.
In the Firebase console, go to Firestore Database and navigate to the products and categories collections. Check that your products and categories have been uploaded successfully.