This project is the backend api service for a dating site written entirely in javascript.
The backend will use the following technologies and frameworks:
This procedure explains how to install MySQL using Homebrew on macOS Sierra 10.12
- Installing Homebrew is effortless, open Terminal and enter :
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.
At this time of writing, Homebrew has MySQL version 5.7.17 as default formulae in its main repository :
- Enter the following command :
$ brew info mysql
- Expected output: mysql: stable 5.7.17 (bottled)
To install MySQL enter : $ brew install mysql
-
Install brew services first :
$ brew tap homebrew/services
-
Load and start the MySQL service :
$ brew services start mysql
. Expected output : Successfully startedmysql
(label: homebrew.mxcl.mysql) -
Verify the installed MySQL instance :
$ mysql -V
. Expected output : Ver 14.14 Distrib 5.7.15, for osx10.12 (x86_64)
At this time of writing, Homebrew has npm version 7.7.2 as default formulae in its main repository :
- Enter the following command :
$ brew info npm
- Expected output: node: stable 7.7.2 (bottled)
To install MySQL enter : $ brew install npm
Clone this repository to your local machine via;
git clone git@github.com:salimkapadia/express-knex.git
cd express-knex
npm install
NODE_ENV=default $(npm bin)/knex migrate:latest --knexfile src/server/utils/knexfile.js --cwd src/server/database/
$ npm start
$ NODE_ENV=development node index.js
$ npm stop
Database changes are managed through knex.
-
When creating migrations with knex, please use the following convention for the
migrationName
:create-tableName
when your script is creating a tablebash NODE_ENV=default $(npm bin)/knex migrate:make create-event --knexfile src/server/utils/knexfile.js --cwd src/server/database/
drop-tableName
when your script is dropping a table.bash NODE_ENV=default $(npm bin)/knex migrate:make drop-event --knexfile src/server/utils/knexfile.js --cwd src/server/database/
alter-tableName
when your script is altering a tablebash NODE_ENV=default $(npm bin)/knex migrate:make alter-event --knexfile src/server/utils/knexfile.js --cwd src/server/database/
insert-tableName
when your script is inserting into a table.bash NODE_ENV=default $(npm bin)/knex migrate:make insert-event --knexfile src/server/utils/knexfile.js --cwd src/server/database/
update-tableName
when your script is update a record in a table.bash NODE_ENV=default $(npm bin)/knex migrate:make update-event --knexfile src/server/utils/knexfile.js --cwd src/server/database/
-
Table names should be singular. See stackoverflow for explanation.
-
Foreign keys should be lowercase like so: fk_foreignKeyTableName_primaryKeyTableName
- Should be saved in the controllers directory.
- Filename should be camelCased and end with the word Controller like so - bookController.js
Please keep in mind that during the build process, the test directory is not packaged. The application can be tested like so:
$ npm test
If you need to add seed data for your tests, use knex seed-cli.
- Adding a seed file:
$(npm bin)/knex seed:make --knexfile src/server/utils/knexfile.js --cwd test/data insert-dummy-data.js
- Running seed files:
$(npm bin)/knex seed:run --knexfile src/server/utils/knexfile.js --cwd test/data