Set-up the Backend
Please follow these instructions to configure and run the Backend on your localhost
Within terminal (Mac) or cmd (windows) navigate into the 'Backend' project directory and install the dependencies
Configuration
Before we can run our backend web app we need to configure some important settings.
To make our project easier to maintain, we are using a package called 'config' which allows you to define a set of default parameters, and extend them for different deployment environments (development, staging, production, etc.).
For more information, please see: https://www.npmjs.com/package/config
Please open the following files within your chosen text editor.
config/default.json
config/custom-environment-variables.json
We define static parameters within 'default.json' and then use 'custom-environment-variables.json' to map node env variables to parameters that contain more sensitive data such as passwords or anything we don't want to hardcode into our app.
Configure our mail server
We are using a package called 'nodemailer' to handle sending password recovery emails. Follow these instructions to configure your mail server:
Within 'config/default.json' change the following static parameters:
Please note: if you are unsure about any of this information, please contact your mail server provider.
Node Environment Variables
As we previously explained, we are using Node Environment Variables to supply our app with some more sensitive information. This includes our mail server user & password. In addion to our JWT Secret.
To define, please go back to your terminal or cmd and write the following commands
Please note: Windows users should use 'set' instead of 'export'
Set-up MongoDB (Setting up your database)
This web app uses MongoDB to save, query and process data. Whilst you may have a preference of your service provider (AWS, Microsoft Azure etc…) we will be using ‘mlab’.
Please visit ‘mlab’ register/login to your account.
Link- https://mlab.com/
From your control panel select ‘Create new’
Choose any of the Cloud Provider’s
Select the appropriate ‘Plan Type’ for you. For now, let’s select the ‘Free’ plan
Click Continue
Select the ‘Region’ that’s closest to your location and click continue
Enter a new database name and click continue
Confirm your selections and click ‘Submit order’ (Free)
The database will now be created, and you will have been redirected back to your dashboard.
Adding a User to your database
Under ‘MongoDB Deployments’ click on the database you just created
Select ‘Users’
Select ‘Add database users’
Enter a Username and Password and click ‘Create’
Please remember this information as we will need it later.
Connecting our Registration System to our Database
We need a ‘connection string’ provided by ‘mlab’ to link our Registration System with our Database.
Please ensure that you are still navigated inside the database you just created.
It looks something like this:
Copy this URL as we will need it later.
Configuring our Registration System to Connect to our Database
Open the project folder within your chosen text editor
Open ‘startup/db.js'
Paste the connection string obtained from ‘mlab’ into the connect method:
Update the URL to contain the details of the User we added to the database in the previous steps.
Configure cors
As you know, the Frontend and Backend are two separate web apps. As a result we need to grant access (whitelist) our frontend to communicate with our backend.
Open: 'webConfig.json'
Please ensure that before running on localhost or deploying you update 'frontend_url' to match the URL hosting your Frontend web app.
By default your Frontend/Backend will be running on:
Please ensure you have configured this correctly each time you run or deploy on a different environment.
Lunch our Backend Web App
Your backend app should be running on
Last updated