Skip to content

Commit 3bbadfb

Browse files
authored
Merge pull request #81 from cham11ng/upgrade
Upgrade packages
2 parents 7c3605c + 5d160bb commit 3bbadfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2313
-4623
lines changed

.dockerignore

-1
This file was deleted.

.editorconfig

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ root = true
55

66
# Unix-style newlines with a newline ending every file
77
[*]
8-
end_of_line = lf
98
charset = utf-8
10-
insert_final_newline = true
11-
indent_style = space
9+
end_of_line = lf
1210
indent_size = 2
13-
14-
# Matches the exact files either package.json or .travis.yml
15-
[{package.json,.travis.yml}]
1611
indent_style = space
17-
indent_size = 2
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
[Makefile]
16+
indent_size = 4
17+
indent_style = tab

.eslintrc

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
22
"root": true,
33
"parser": "@typescript-eslint/parser",
4-
"plugins": [
5-
"security",
6-
"@typescript-eslint"
7-
],
4+
"plugins": ["sonarjs", "simple-import-sort", "jsdoc"],
85
"parserOptions": {
9-
"ecmaVersion": 2018, // Allows for the parsing of modern ECMAScript features
10-
"sourceType": "module" // Allows for the use of imports
6+
"ecmaVersion": "latest",
7+
"sourceType": "module"
118
},
129
"ignorePatterns": ["./node_modules/*"],
1310
"extends": [
1411
"eslint:recommended",
15-
"plugin:security/recommended",
1612
"plugin:@typescript-eslint/recommended",
17-
"plugin:@typescript-eslint/eslint-recommended"
13+
"plugin:sonarjs/recommended",
14+
"plugin:jsdoc/recommended-typescript"
1815
],
1916
"rules": {
2017
"no-error-on-unmatched-pattern": "off",
21-
"@typescript-eslint/no-explicit-any": "off", // TODO: Remove this.
22-
"no-return-await": "off",
23-
"no-shadow": "off",
24-
"@typescript-eslint/no-shadow": ["error"]
18+
"@typescript-eslint/no-explicit-any": "warn",
19+
"sonarjs/cognitive-complexity": "off",
20+
"@typescript-eslint/no-shadow": ["error"],
21+
"@typescript-eslint/ban-ts-comment": "off",
22+
"simple-import-sort/imports": "warn",
23+
"jsdoc/no-types": "off",
24+
"jsdoc/tag-lines": "off",
25+
"jsdoc/require-returns-description": "off"
2526
}
2627
}

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: Starter CI
22

33
on:
44
push:
5-
branches: [dev, master]
5+
branches: [dev, main]
66
pull_request:
7-
branches: [dev, master]
7+
branches: [dev, main]
88

99
jobs:
1010
build:
1111
strategy:
1212
matrix:
13-
node-version: [16.x]
13+
node-version: [20.x]
1414
platform: [ubuntu-latest]
1515

1616
runs-on: ${{ matrix.platform }}

.husky/pre-commit

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npx sync-dotenv
54
yarn lint-staged
5+
6+
# check if the .env file exist
7+
if [ ! -f .env ]; then
8+
exit 0
9+
fi
10+
11+
npx sync-dotenv

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"semi": true,
33
"trailingComma": "none",
44
"singleQuote": true,
5-
"printWidth": 80,
5+
"printWidth": 120,
66
"parser": "typescript",
77
"tabWidth": 2
88
}

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help prepare-dev test lint run
1+
.PHONY: help clean
22
.DEFAULT_GOAL := help
33

44
define BROWSER_PYSCRIPT
@@ -22,7 +22,9 @@ endef
2222
export PRINT_HELP_PYSCRIPT
2323

2424
clean: ## Remove log file.
25-
rm -rf logs/**.log logs/**.json build
25+
@rm -rf logs/*.{log,json}
26+
@rm -rf build
27+
@echo "Clean Successful."
2628

27-
help:
29+
help: ## Help
2830
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ Starter for Node.js Express API in Typescript with jsonwebtoken, joi, Knex, Obje
1919
Clone the repository, install the dependencies.
2020

2121
```bash
22+
# Clone repository
2223
$ git clone [email protected]:cham11ng/typescript-api-starter.git <application-name>
2324

2425
$ cd <application-name>
2526

26-
$ cp .env.example .env # Update database credentials
27+
# Update database credentials
28+
$ cp .env.example .env
2729

2830
$ yarn migrate
2931
```
3032

31-
Load fake data in database.
32-
3333
```bash
34+
# Load fake data in database.
3435
$ yarn load:fake <FactoryName> <Number>
3536
```
3637

@@ -41,9 +42,11 @@ $ yarn load:fake <FactoryName> <Number>
4142
Start the application.
4243

4344
```bash
44-
$ yarn build # For production
45+
# For production
46+
$ yarn build
4547

46-
$ yarn start # For development
48+
# For development
49+
$ yarn dev
4750
```
4851

4952
<p align="center">

SECURITY.md

-21
This file was deleted.

docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
POSTGRES_PASSWORD: ${DB_PASSWORD:-secret}
1515

1616
api:
17-
image: "node:16-alpine"
17+
image: "node:latest"
1818
env_file: '.env.docker'
1919
container_name: "starter-api"
2020
volumes:
@@ -24,4 +24,4 @@ services:
2424
- postgres
2525
ports:
2626
- "8000:8000"
27-
command: sh -c "yarn && yarn start"
27+
command: bash -c "yarn && yarn dev"

package.json

+49-45
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-api-starter",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "Starter for Node.js express API with Typescript",
55
"main": "index.js",
66
"repository": {
@@ -12,10 +12,10 @@
1212
"email": "[email protected]"
1313
},
1414
"engines": {
15-
"node": ">= 16.5.0"
15+
"node": ">= 20.9.0"
1616
},
1717
"scripts": {
18-
"start": "concurrently 'npx tsc --watch' 'nodemon -q build/index.js'",
18+
"dev": "concurrently 'npx tsc --watch' 'nodemon -q build/index.js'",
1919
"transpile": "tsc",
2020
"clean": "rimraf build",
2121
"sync-env": "sync-dotenv",
@@ -52,52 +52,56 @@
5252
"typescript"
5353
],
5454
"dependencies": {
55-
"bcrypt": "^5.0.1",
55+
"bcrypt": "^5.1.1",
5656
"cors": "^2.8.5",
57-
"date-fns": "^2.11.1",
58-
"dotenv": "^16.0.1",
57+
"date-fns": "^3.6.0",
58+
"dotenv": "^16.4.5",
5959
"express": "4.19.2",
60-
"helmet": "^5.1.0",
61-
"http-status-codes": "^2.1.4",
62-
"joi": "^17.6.0",
63-
"jsonwebtoken": "^9.0.0",
64-
"knex": "^2.4.0",
65-
"morgan": "^1.10.0",
66-
"nodemailer": "^6.9.9",
60+
"express-rate-limiter": "^1.3.1",
61+
"helmet": "^7.1.0",
62+
"http-status-codes": "^2.3.0",
63+
"joi": "^17.12.2",
64+
"jsonwebtoken": "^9.0.2",
65+
"knex": "^3.1.0",
66+
"nodemailer": "^6.9.13",
6767
"nodemailer-markdown": "^1.0.3",
68-
"objection": "^3.0.1",
69-
"pg": "^8.6.0",
70-
"winston": "^3.3.3",
71-
"winston-daily-rotate-file": "^4.5.5"
68+
"objection": "^3.1.4",
69+
"pg": "^8.11.3",
70+
"winston": "^3.13.0",
71+
"winston-daily-rotate-file": "^5.0.0"
7272
},
7373
"devDependencies": {
74-
"@faker-js/faker": "^7.3.0",
75-
"@types/bcrypt": "^5.0.0",
76-
"@types/cors": "^2.8.12",
77-
"@types/express": "^4.17.13",
78-
"@types/jest": "^28.1.3",
79-
"@types/jsonwebtoken": "^8.5.4",
80-
"@types/morgan": "^1.9.3",
81-
"@types/node": "^18.0.0",
82-
"@types/nodemailer": "^6.4.4",
83-
"@types/supertest": "^2.0.11",
84-
"@typescript-eslint/eslint-plugin": "^5.30.0",
85-
"@typescript-eslint/parser": "^5.30.0",
86-
"chalk": "^4.1.1",
87-
"concurrently": "^7.2.2",
88-
"eslint": "^8.18.0",
89-
"eslint-plugin-security": "^1.4.0",
90-
"husky": "^8.0.1",
91-
"jest": "^28.1.2",
92-
"lint-staged": "^13.0.3",
93-
"nodemon": "^2.0.12",
94-
"prettier": "^2.3.2",
95-
"rimraf": "^3.0.2",
96-
"supertest": "^6.1.4",
97-
"sync-dotenv": "^2.6.2",
98-
"ts-jest": "^28.0.5",
99-
"ts-node": "^10.9.1",
100-
"tslib": "^2.4.0",
101-
"typescript": "^4.8.4"
74+
"@faker-js/faker": "^8.4.1",
75+
"@types/bcrypt": "^5.0.2",
76+
"@types/cors": "^2.8.17",
77+
"@types/express": "^4.17.21",
78+
"@types/express-rate-limit": "^6.0.0",
79+
"@types/jest": "^29.5.12",
80+
"@types/jsonwebtoken": "^9.0.6",
81+
"@types/node": "^20.11.30",
82+
"@types/nodemailer": "^6.4.14",
83+
"@types/supertest": "^6.0.2",
84+
"@typescript-eslint/eslint-plugin": "^7.4.0",
85+
"@typescript-eslint/parser": "^7.4.0",
86+
"chalk": "^5.3.0",
87+
"concurrently": "^8.2.2",
88+
"eslint": "^8.57.0",
89+
"eslint-plugin-jsdoc": "^48.2.2",
90+
"eslint-plugin-prettier": "^5.1.3",
91+
"eslint-plugin-security": "^2.1.1",
92+
"eslint-plugin-simple-import-sort": "^12.0.0",
93+
"eslint-plugin-sonarjs": "^0.25.0",
94+
"husky": "^9.0.11",
95+
"jest": "^29.7.0",
96+
"lint-staged": "^15.2.2",
97+
"nodemon": "^3.1.0",
98+
"prettier": "^3.2.5",
99+
"rimraf": "^5.0.5",
100+
"supertest": "^6.3.4",
101+
"sync-dotenv": "^2.7.0",
102+
"ts-jest": "^29.1.2",
103+
"ts-node": "^10.9.2",
104+
"tslib": "^2.6.2",
105+
"typescript": "^5.4.3"
102106
}
103107
}

scripts/fake-loader.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import chalk from 'chalk';
22

3-
import * as fake from '../src/utils/fake';
43
import { bindModel } from '../src/config/db';
54
import factories, { FactoryType } from '../src/database/factories';
5+
import * as fake from '../src/utils/fake';
66

77
const { info } = console;
88

9+
/**
10+
* Print the data in JSON format.
11+
*
12+
* @param data - Data to print.
13+
* @returns {void}
14+
*/
915
function print<T>(data: T): void {
1016
const jsonData = JSON.stringify(data, null, ' ');
1117

src/app.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import cors from 'cors';
2-
import helmet from 'helmet';
32
import express from 'express';
3+
import helmet from 'helmet';
44

5-
import routes from './routes';
65
import { bindModel } from './config/db';
7-
import logHandler from './middlewares/logHandler';
6+
import genericErrorHandler from './middlewares/genericErrorHandler';
87
import notFoundHandler from './middlewares/notFoundHandler';
8+
import rateLimitMiddleware from './middlewares/rateLimitHandler';
99
import transactionHandler from './middlewares/transactionHandler';
10-
import genericErrorHandler from './middlewares/genericErrorHandler';
10+
import routes from './routes';
1111

1212
const app: express.Application = express();
1313

@@ -16,7 +16,7 @@ bindModel();
1616
app.use(cors());
1717
app.use(helmet());
1818
app.use(transactionHandler);
19-
app.use(logHandler);
19+
app.use(rateLimitMiddleware);
2020
app.use(express.json({ limit: '300kb' }));
2121
app.use(express.urlencoded({ extended: true }));
2222

src/config/db.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Knex from 'knex';
2-
import { Model, knexSnakeCaseMappers } from 'objection';
2+
import { knexSnakeCaseMappers, Model } from 'objection';
33

44
import config from './config';
55

0 commit comments

Comments
 (0)