This version uses Express (instead of Hapi). Now ready for studying!
- Git for Windows (2.20.1.windows.1), including the Git Bash
- VS Code 1.29.1
- Node v8.11.4
- npm 5.6.0
- (many node packages installed based on package.json, See below)
- Postman v6.7.1
- MariaDB 5.5.46 (But newer versions should work fine too)
- MySQL Workbench 8.0.12 CE = Community edition (Not 100% necessary, only if want GUI SQL editor)
- ssh, for creating the SSH tunnel, but first do without the tunnel, as it adds another thing to debug/fix
(((0. Have the SSH Tunnel to Maridb database defined so that finally it shows: L3308 localhost:3306
(That is the correct way! localhost:3306 here means how it's called inside Mariadb, our destination is the 'localhost' = Mariadb.))))
- Have a possible common root folder (root root folder) called "Case2019K" for both Frontend and Backend repos. Then you can open both projects to editor with one "Open folder" command
- clone Backend repo from GitHub while in that common root folder > git clone repolinkfromgithubcom
- > pwd to make sure where you are! Then cd to repo
- > pwd again for folder awareness!
- run > npm install if in the repo root folder, to automatically install the dependencies from the package.json. (Somebody else has already run the npm init & needed npm install thisandthat commands earlier)
- Create env_variables.sh file to some folder outside the project. Example contents below DB_DATABASE is actually your schema name on the database server. If you use mariadb.haaga-helia.fi it has the same name as username (Haaga-helia shared server thing only!). If you use your own installation of mariadb, it could be e.g. "test" Double check that the host and port are 'localhost' and '3308'. (If you use the SSH tunnel). Well, just be aware of all the settings and what are correct in YOUR case.
- >npm run db:init to run the db creation/reset script and get the shared test data (We should soon remove/consolidate/merge the scripts from the Database folder, as we should only have one set of drop, create and insert statements in our project)
- >npm start
- test e.g. http://localhost:8787/api/category/all and http://localhost:8787/api/category/all or even the POST services if using PostMan
- now ready to setup and run Frontend project
(You can of course also first run without env variables, use hard-coded values, though do not then accidentally enter the values in git.
And also with local MariaDB installation, localhost, port 3306, without the SSH tunnel
And then, when all tests ok with basic version, start to add compicating things)
// ******** Sample env_variables.sh file (run it in console before starting the backend) ********** export BE_API_URL_PREFIX="//api" export BE_SERVER_PORT="8787" export DB_DRIVER_MODULE="mysql" export DB_HOST="localhost" export DB_PORT="3306" export DB_USER="XXXXXXXXXXXXXXXXXXXXX" export DB_PASSWORD="XXXXXXXXXXXXXXXXXXXXXXXX" export DB_DATABASE="test" export DB_DEBUG="true" export DB_MULTIPLE_STATEMENTS="true" export DB_CONNECTION_POOL_MIN="1" export DB_CONNECTION_POOL_MAX="7" // ****************** END of env_variables.sh file ******************
source env_variables.sh will run the export commands. Works at least in Windows GitBash console.
https://www.getpostman.com/collections/not_yet_there
- Host Name: mariadb.haaga-helia.fi
- Saved Sessions: MariaDB server SSH Tunnel
- Do no change the other defaults (Protocol: SSH, Port: 22)
- After saving, go to Connection / SSH / Tunnels
- Write to Source Port: 3308 This is our own computer port (marked often with big L) !!!
- Write to Destination: localhost:3306 (This means where to go in mariadb.haaga-helia.fi, there localhost = md.h-h.fi!!!)
- Click on “add”, select the session “MariaDB server SSH Tunnel” you just create and save it again.
- Now you can click open on the session “MariaDB server SSH Tunnel” to use it
Unix system: (Or e.g. in the Git Bash console on Windows, though might need to omit -f in Windows sometimes?)
> ssh -f [email protected] -L 3308:localhost:3306 -N
The executed ssh command sets up an ssh tunnel through the cli. After execution allow the fingerprint exchange with "yes" and type in your student accounts password.
NOTE: DO NOT CLOSE THE TERMINAL. Closing the terminal will close the tunnel.
NOTE 2: If you are use an older version than windows 10 please use putty or another ssh client to create the same tunnel.
-
npm run-script db:init - will populate your database with some tables and values
-
npm start - will start the server (point your browser to http://localhost:8787 to see a welcome message from the backend or to http://localhost:8787/api/category/all to see a list of entries from Category table)
- Express.js docs in case its needed express.js
- All knex.js commands knex.js NOTE: ctrl+f is your friend
- All ES6 features can be found on this cheatsheet ES6
- Git cheatsheet git