LeanMood backend project will be a REST /JSON api, hopefully based on express, mongoose, mongodb.
Prerequistes: be sure to have installed in your computer nodejs and mongo db.
- Ensure you have running mongodb, in case not run the following command from the command prompt
mongod
In case it fails, check if you have the mongodb bin path in the enviroment variables:https://stackoverflow.com/questions/15053893/error-when-trying-to-connect-to-a-mongod
-
Let's cd to our project root folder.
-
Open a new command prompt console and run mongo
mongo
- From the mongo console let's list all of the databases that are installed:
show dbs
- In case leanMood database is already in the server let's remove it and start from scratch
mongo leanMood --eval "db.DropDatabase()"
- Now let's create leanMood database.
use leanMood
- Let's import the user seed data (you will run this just from the command prompt, do not connect to mongo cli).
mongoimport -d leanMoodAccess -c logins --type json --file ./meta/data/login.seed.json --jsonArray
mongoimport -d leanMood -c trainings --type json --file ./meta/data/training.seed.json --jsonArray
mongoimport -d leanMood -c users --type json --file ./meta/data/user.seed.json --jsonArray
Ensure you have mongodb up and running and the leanMood installed including seed data.
-
Open a new command prompt window, cd to the project root folder (same level where package.json is placed).
-
Install all the dependencies:
npm install
- Let's run the project
npm start
- Now it's time to test that we can hit the rest api, let' s open postman, we will
sen a query like:
- URL: http://localhost:5000/api/login
- Command: POST
- Headers:
Cotent-Type: 'application/json'
- Body (raw, JSON Application):
{
"loginName": "jai",
"password": "test"
}
If it doesn't work check if you have PostMan Interceptor turned on (in that case turn it off).
Resources: