- Installing Dependencies
- Setting up the environment variable
- Setting up the project
- Starting the web app
First you need to download & install NodeJS and verify the version using npm -v in your terminal.
First, you need to create a ".env" file with following contents:
- MONGODB_URI=
mongodb+srv://username123:<password>@cluster0.ktizgno.mongodb.net/ - GOOGLE_CLIENT_ID=
<Client ID> - GOOGLE_CLIENT_SECRET=
<Client secret> - GOOGLE_CALLBACK_URL=
http://localhost:5000/google/callback
-
To create MongoDB URI to store your credentials
- create a MongoDB account and go to the dashboard screen
- you see project folder on top left maybe named as Project 0
- click on it and create a new project name it whatever you wish to create set yourself as project owner, on top it might say that your IP is not added so add it.
- click on build a database and it goes to a setup page select free option and keep everything to default and create
- set username and password and copy the password store it somewhere and click on create user.
- you will be redirected to dashboard and now click on connect then click on MongoDB for VS code
- copy your link provided under Connect to your MongoDB deployment.
- for example: `mongodb+srv://username123:@cluster0.ktizgno.mongodb.net
- replace password with the password you stored while creating the user and then copy this whole URI to the MONGODB_URI in ".env" file.
- if you do get any error in console like MongoNetworkError its most likely that your IP address is not added as a authorised party to access the database.
-
to set up google 0auth
- go to Google Cloud Console
- click on 'select a project' drop down menu and create a new project
- name the project what ever you like and then keep everything default and create it.
- once done select the project from project selection drop down.
- on the left you will have a hamburger slider with multiple options select API & services.
- go to 0Auth consent screen and select use type External, write any app name add your email as a user support email if you have a logo you can add it, add dev contact information(your email) and then save and continue, press save and continue again, press save and continue again.
- press back to dashboard.
- then go to credential then create credentials by clicking on "+Create Credentials" click on 0auth client ID.
- application type- Web App
- name the app whatever your like or leave it as it is
- in JavaScript origins add "http://localhost:5000"
- then in Authorized redirect URIs add "http://localhost:5000/google/callback" it can take 5 or more mins to update.
- click create, you will get a pop up with "0Auth client created"
- copy Client ID and paste it in the
<Client ID> in .env, also copy the client secret and paste it in the<Client secret> in .env
and you are good to go.
- navigate to your project folder and then run in the terminal:
$npm installthis will install all the dependencies. - once all dependencies installed then you need to run:
$npm startthis will start the web app. - in browser go to "http://localhost:5000" and your app should work.