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.local
and populate.env.local
with your environment's configuration options. -
Run
NODE_ENV=local npm install
to install all dependencies (optional & development)
NODE_ENV
: (required) Which node environment are you using (currently:development
,acceptance
,production
,test
orlocal
). Valueslocal
andtest
have the following special conditions:test
are for running [mocha] testslocal
adds optional & dev dependancies throughpostinstall.sh
. Requires.env.local
to be setup before install
PORT
: (optional): Which port the server should listen to. Defaults:3000
VCAP_SERVICES
: (required for production) Used for PCF deployment which should be an encoded JSON. Refer to their documentation/configurationDB_*
: (required ifVCAP_SERVICES
is 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 tofalse
REQUEST_LOGGING_SESSION
: Request logging will include Session Data. This value aliases to a boolean env-1, env-2 Defaults tofalse
REQUEST_LOGGING_COOKIE
: Request logging will include Cookie strings. This value aliases to a boolean env-1, env-2 Defaults tofalse
REQUEST_LOGGER_ASSETS
: Request logging will include static file asset Data. This value aliases to a boolean env-1, env-2 Defaults tofalse
REQUEST_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 tofalse
VERBOSE
: Enables extra logging including. This value aliases to a boolean env-1 or stringall
. Defaults tofalse
FRONTEND_URL
: Configure for CORS Ajax requests; can be comma separated but ignores PORT from originSKIPPOSTINSTALL
: is exclusively used forpostinstall.sh
to 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 -p
and 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
-
build
Trigger babel to compile code intodist/
directory -
start
Start the Application using the compiled babel code (setNODE_ENV
environment variable);npm run build
needs to be ran first -
dev:*
-
dev
Start the application withnodemon
withNODE_ENV
set to 'local' -
dev:debug
Same as above with attached debugger
-
-
postinstall
Runs automatically afternpm install
but callspostinstall.sh
which eventually callspostinstall.js
db-1. -
teardown
Executesuninstall.sh
which removes node dependancies, caches, builds and data storesdb-1. -
docs
Generate documentation -
lint:*
-
lint
Runs npm run lint -
lint:prod
Runs above but will error if any warnings are triggered
-
-
db:*
-
db:migrate
Run sequelize migrations -
db:setup:fixture
Run sequelize seed data sets for local development -
db:seed
Run sequelize Seeds but path to the seed needs to be passednpm run db:seed -- --seed path/to/seed.js
-
db:drop
Run 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:*
-
test
Run Mocha test withNODE_ENV
set to 'test' -
test:debug
Same as base 'test' (above) with attached debugger -
test:watch
Same as base 'test' (above) with 'watch mode' to refresh after files change -
test:coverage
Same as base 'test' (above) with a coverage report
-
-
coverage
Same asnpm run test:coverage
with 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
,yes
or1
. - Boolean value of false aliases as
false
,no
or0
.
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