| Dependancy | Version | Note |
|---|---|---|
| Node | 8.x (LTS) | |
| npm | 6.x | Observe Node Releases |
| MySQL | 5.7 | Primary DataStore |
| Redis | - | Session Store (Coming Soon) |
-
If you don't have mysql installed already be sure to follow the steps below Localhost MYSQL
-
Create an AWS-S3 bucket & IAM Role as outlined below
-
Setup dot env file:
cp .env.sample .env.localand populate.env.localwith your environment's configuration options. -
Run
NODE_ENV=local npm installto install all dependencies (optional & development)
NODE_ENV: (required) Which node environment are you using (currently:development,acceptance,production,testorlocal). Valueslocalandtesthave the following special conditions:testare for running [mocha] testslocaladds optional & dev dependancies throughpostinstall.sh. Requires.env.localto be setup before install
PORT: (optional): Which port the server should listen to. Defaults:3000VCAP_SERVICES: (required for production) Used for PCF deployment which should be an encoded JSON. Refer to their documentation/configurationDB_*: (required ifVCAP_SERVICESis not set): MySQL Database settingsDB_USER: UsernameDB_PASS: PasswordDB_HOST: HostDB_NAME: Database Name (steps below suggestmyAppDb)DB_PORT: Database PortDB_PORT=3306(defaults to3306)
AWS_S3_*AWS S3 ConfigurationAWS_S3_BUCKET: S3 Bucket NameAWS_S3_SDK_KEY: Key of the API Key-PairAWS_S3_SDK_SECRET: Secret of the API Key-PairAWS_S3_REGION: AWS Region (defaults tous-east-1)
SESSION_SECRET: Session SaltREQUEST_LOGGING_*: Logging details into the pino loggerREQUEST_LOGGING: Enables the HTTP Request logging. This value aliases to a boolean env-1. Defaults tofalseREQUEST_LOGGING_SESSION: Request logging will include Session Data. This value aliases to a boolean env-1, env-2 Defaults tofalseREQUEST_LOGGING_COOKIE: Request logging will include Cookie strings. This value aliases to a boolean env-1, env-2 Defaults tofalseREQUEST_LOGGER_ASSETS: Request logging will include static file asset Data. This value aliases to a boolean env-1, env-2 Defaults tofalseREQUEST_LOGGING_MASK: Request logging will mask object content with descriptor strings. This value aliases to a boolean env-1. Defaults totrue
DEBUG_SQL: Enables the Sequelize debugging of raw queries. This value aliases to a boolean env-1. Defaults tofalseVERBOSE: Enables extra logging including. This value aliases to a boolean env-1 or stringall. Defaults tofalseFRONTEND_URL: Configure for CORS Ajax requests; can be comma separated but ignores PORT from originSKIPPOSTINSTALL: is exclusively used forpostinstall.shto avoid install recursion
Install MYSQL via OSX Brew: brew install [email protected] or otherwise use your favourite binary or package installer.
For convenience its recommended you setup a username, password and database as follows.
-
Login into MYSQL shell using your root credentials
mysql -u root -pand you will be prompted for your MYSQL root password. -
Create the Database
CREATE DATABASE myAppDb; -
Specify the new user
CREATE USER 'myAppUser'@'localhost' IDENTIFIED BY 'somethingSecret555111222'; -
Add permissions (Choose One):
-
to all databases
GRANT ALL PRIVILEGES ON * . * TO 'myAppUser'@'localhost'; -
OR
-
to specific databases with our default name
GRANT ALL PRIVILEGES ON myAppDb . * TO 'myAppUser'@'localhost';
-
Flush Permissions
FLUSH PRIVILEGES; -
Exit MYSQL Terminal
quit
In app setup we configure each connection to change a SQL Variable. Use the following in you SQL manager's raw query terminal:
SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
# YOUR DEBUG SQL GOES AFTER THIS LINE
Create an IAM Role with the following settings
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Action": [
"s3:CreateBucket",
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::*"
},
{
"Sid": "2",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::*/*"
}
]
}
You can test your test IAM permissions. Additionally you can change the portion(s) "Resource": "arn:aws:s3:::*" can be arn:aws:s3:::<BUCKETNAME> if you don't want to give open access to your IAM role; however the given example is required to is postinstall.js to automatically create the bucket for you.
Use npx <script> or npm run <script> and replace '<script>' with any of the below
-
buildTrigger babel to compile code intodist/directory -
startStart the Application using the compiled babel code (setNODE_ENVenvironment variable);npm run buildneeds to be ran first -
dev:*-
devStart the application withnodemonwithNODE_ENVset to 'local' -
dev:debugSame as above with attached debugger
-
-
postinstallRuns automatically afternpm installbut callspostinstall.shwhich eventually callspostinstall.jsdb-1. -
teardownExecutesuninstall.shwhich removes node dependancies, caches, builds and data storesdb-1. -
docsGenerate documentation -
lint:*-
lintRuns npm run lint -
lint:prodRuns above but will error if any warnings are triggered
-
-
db:*-
db:migrateRun sequelize migrations -
db:setup:fixtureRun sequelize seed data sets for local development -
db:seedRun sequelize Seeds but path to the seed needs to be passednpm run db:seed -- --seed path/to/seed.js -
db:dropRun sequelize undo all; run all 'down' steps for migrations & seeds` -
db:sync(Coming Soon) Sync files with Data-Stores/Caches -
db:sync:s3(Coming Soon) Sync MySQL records with S3 Store
-
-
test:*-
testRun Mocha test withNODE_ENVset to 'test' -
test:debugSame as base 'test' (above) with attached debugger -
test:watchSame as base 'test' (above) with 'watch mode' to refresh after files change -
test:coverageSame as base 'test' (above) with a coverage report
-
-
coverageSame asnpm run test:coveragewith coverage report opened in your default browser
-
_cache/For temporary files such as uploaded files and local store of served S3 files -
dist/build directory after compiling babel -
dev/SQL migrations, seeds and other assets such as place holder images -
jsdocs/JSDOCs documentation -
src/Application codebase -
tests/Mocha-Unit-Tests -
coverage/Istanbul coverage report files (html)
Footnotes
env-1 This environment variable takes values as boolean.
- Boolean value of true aliases as
true,yesor1. - Boolean value of false aliases as
false,noor0.
env-2 Becomes equivalent to true when VERBOSE is set to all.
db-1 Set NODE_ENV but will default to 'local' if not set