Add a .env file in the Server
folder. This file would contain all non-shareable config.
- Setup MongoDb databases for production and testing then enter the url in the
.env
file asmongodbMealURI
andmongodbMealMockURI
respectively - Add indexes to the database to ensure high performance running the following commands
- db.users.ensureIndex({"meals.date" : 1})
- db.users.ensureIndex({"meals._id" : 1})
- db.users.ensureIndex({"googleId" : 1})
- db.users.ensureIndex({"facebookId" : 1})
- Add
mailerUser
(sender email address) andmailerPass
(sender email password) to the.env
file
- Go to developer.nutritionix.com and signup for an account to get your app id and app key
- Add
nutritionixAppId
andnutritionixAppKey
with their corresponding values to the.env
file
- Go to https://developers.facebook.com/apps/ and add a Facebook Login product
- Add the following Valid OAuth Redirect URIs
- https://localhost:4400/ for the dev server
- https://caltrack-meals.herokuapp.com/ for the hosted app
- https://localhost:3001/ to test serving from the same backend server locally
- Add to the
.env
file the clientId and clientSecret using the following props respectively:facebookClientId
andfacebookClientSecret
- Go to https://console.developers.google.com/apis/credentials
- Add the same urls as shown above in "Authorized JavaScript origins" section
- Add to the
.env
file the clientId and clientSecret using the following props respectively:googleClientId
andgoogleClientSecret
- Go to https://www.google.com/recaptcha/admin#list and signup for api keys
- Add to the
.env
file the site key and secret key using the following props respectively:captchaSiteKey
andcaptchaSecretKey
- Add
secret
to the.env
for jwt
- NODE_ENV
- facebookClientId
- facebookClientSecret
- googleClientId
- googleClientSecret
- mailerPass
- mailerUser
- mongodbMealMockURI
- mongodbMealURI
- nutritionixAppId
- nutritionixAppKey
- secret
- captchaSiteKey
- captchaSecretKey
- Run
npm run dev
to fire up nodemon
- Run
npm start
- Signup for a user and manually change the user's role in MongoDb to
admin
. Make sure this user has the following credentials: email: "admin@test.com", password: "1234567a" - Ensure the availability for a
manager
user with the following credentials email: "manager@test.com", password: "1234567a" - Add NODE_ENV="testing" to your
.env
file or replace the current NODE_ENV value. This is to ensureGoogle Recaptcha
would not fail our tests - Run
npm test
for api and unit tests
For Development: Run npm start
to build the project and use the dev-server. Then navigate to http://localhost:4400/
For Production: Run npm run prod
to build the project in the public directory in the Server
folder.
Run npm t
to execute the unit tests via Karma.
You might need to update webdriver manager before running tests by running npm run update-wd
- Run
npm start
- Run
npm run e2e
to execute the end-to-end tests via Protractor.
- Register for an app in heroku
- Use the following command to install
heroku-config
package.heroku plugins:install heroku-config
- Make sure you are loggin into heroku cli. If not use the
heroku login
command - Use the following git command in the root folder to push only backend node.js api to heroku.
git subtree push --prefix Server heroku master
- Use the following command for heroku logs.
heroku logs -t --app "app-name"
- Use the following command for heroku logs.
To push and pull environment variables: heroku plugins:install heroku-config cd Server heroku config:push
The code has been tested on a Windows 10 x64 machine. No guarantees that the development environment would work in other operating systems; hopefully it does