npm init -y
npm i typescript ts-node nodemon @types/node @types/express -D
npm i apollo-server-express express graphql type-graphql class-validator typeorm reflect-metadata
for MySQL or MariaDB
npm install mysql
(you can install mysql2 instead as well)
for PostgreSQL or CockroachDB
npm install pg
for SQLite
npm install sqlite3
"scripts": {
"start": "nodemon --exec ts-node src/index.ts",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
}
Now your package.json should looks like this
{
"name": "be",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon --exec ts-node src/index.ts",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/express": "^4.17.9",
"@types/node": "^14.14.8",
"nodemon": "^2.0.6",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"dependencies": {
"apollo-server-express": "^2.19.0",
"express": "^4.17.1",
"graphql": "^15.4.0",
"reflect-metadata": "^0.1.13",
"type-graphql": "^1.1.1",
"typeorm": "^0.2.29"
}
}
create a PostgreSQL database on AWS
install database
npm i pg
configure database
{
"type": "postgres",
"host": "database-2.cravwavodaxd.ap-northeast-1.rds.amazonaws.com",
"port": 5432,
"username": "",
"password": "",
"database": "postgres",
"synchronize": true,
"logging": false,
"entities": ["src/entity/**/*.ts"],
"migrations": ["src/migration/**/*.ts"],
"subscribers": ["src/subscriber/**/*.ts"]
}
git init
npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard
{
"env": {
"es2020": true,
"node": true
},
"extends": ["standard"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": { "space-before-function-paren": "off" }
}
npm i -D --save-exact prettier
{
"semi": false,
"singleQuote": true,
"arrowParens": "avoid",
"printWidth": 120,
"trailingComma": "none"
}
install Husky and pretty-quick
npm i -D husky pretty-quick
configure Husky
In package.json, add:
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
timestamptz
noteMySQL doens't have timestamptz
, also when you just type timestamp in MySQL, MySQL can get the right timezone.