Database configuration for Express Typescript Boilerplate
By default, this application connects to LokiJS DB in dev
environment, MySQL in staging
environment and MongoDB in prod
environment. You can change to any database in any environment with either of the following options:
Option 1: Set following variables in env files located at env/<dev / staging / prod>.env
Database | Variable |
---|---|
MongoDB | REPOSITORY.DEFAULT=MONGO |
MySQL | REPOSITORY.DEFAULT=MYSQL |
LokiJS | REPOSITORY.DEFAULT=LOKI |
Option 2: Set CLI argument while running the application
Database | TS CLI Argument | Built JS CLI Argument |
---|---|---|
MongoDB | ts-node ./src -r MONGO |
node ./dist -r MONGO |
MySQL | ts-node ./src -r MYSQL |
node ./dist -r MYSQL |
LokiJS | ts-node ./src -r LOKI |
node ./dist -r LOKI |
MongoDB config. Install MongoDB from here
mongo
use test_db;
db.createUser({"user":"test_user","pwd":"test_pass","roles":[{"role":"userAdmin","db":"test_db"}]});
MySQL config. Install MySQL from here
mysql -u root -p
CREATE DATABASE `express-typescript-boilerplate`;
USE `express-typescript-boilerplate`;
CREATE USER 'node_user'@'%' IDENTIFIED WITH mysql_native_password BY 'node_user';
CREATE TABLE `app-refresh-tokens` (
`refreshToken` text NOT NULL
);
CREATE TABLE `product_mst` (
`code` varchar(20) NOT NULL,
`name` varchar(20) NOT NULL,
`desc` varchar(100) NOT NULL,
`tag` varchar(100) NOT NULL,
`price` float NOT NULL,
PRIMARY KEY (`code`),
UNIQUE KEY `code_UNIQUE` (`code`)
);
CREATE TABLE `sale_mst` (
`productCode` varchar(20) NOT NULL,
`userEmail` varchar(100) NOT NULL,
`quantity` int NOT NULL
);
CREATE TABLE `user_mst` (
`firstname` varchar(20) NOT NULL,
`lastname` varchar(20) NOT NULL,
`email` varchar(100) NOT NULL,
`dob` date NOT NULL,
PRIMARY KEY (`email`),
UNIQUE KEY `email_UNIQUE` (`email`)
);