This version uses Express (instead of Hapi). Now ready for studying!
- Install TSLint(ms-vscode.vscode-typescript-tslint-plugin) on VS code
- VS Code -> Preferences -> Settings -> Extensions -> TsLint
- In "Tslint: Config File" section, enter the absolute path to tslint.json file
- Tick on "Tslint: JS Enable"
- 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)
- 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)
- Open the editor and add/edit and check CONSTANTS.js in src/db folder. Change your: db-username, db-password, and the "database" which actually is your schema name on the database server. Double check that the host and port are 'localhost' and '3308'. (That is our end of the tunnel).
- >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:8989/api/urgencyType/all and http://localhost:8989/api/urgencyType/all or even the POST services if using PostMan
- now ready to setup and run Frontend project
// ****************** Sample /src/CONSTANTS.js file ****************** // /src/CONSTANTS.js
// The only place for back-end server and database settings
// SERVER_SETTINGS
// The only place for common server settings, including for CORS later
const SERVER_SETTINGS = {
port: 8989,
api_url_prefix: "/api",
};
// DB_SETTINGS
// The only place for common database settings
const DB_SETTINGS = {
driverModule: "mysql",
host: "localhost",
port: "3308",
user: "valju",
password: "YOUR_DB_PASSWD_HERE",
database: "valju",
multipleStatements: true,
debug: true,
connPoolMin: 0,
connPoolMax: 7,
};
export {SERVER_SETTINGS, DB_SETTINGS};
// ****************** END of CONSTANTS.js file ******************
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 valju@mariadb.haaga-helia.fi -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