Skip to content

Commit 37784a1

Browse files
committed
feat(app): build structure
1 parent 9b1a4f9 commit 37784a1

9 files changed

+1699
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = crlf
10+
charset = utf-8
11+
trim_trailing_whitespace = false
12+
insert_final_newline = true

.eslintrc.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"prettier"
10+
],
11+
"parser": "@typescript-eslint/parser",
12+
"parserOptions": {
13+
"ecmaVersion": "latest",
14+
"sourceType": "module"
15+
},
16+
"plugins": [
17+
"@typescript-eslint"
18+
],
19+
"rules": {
20+
}
21+
}

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true
4+
}

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "pg-examination-server",
3+
"version": "1.0.0",
4+
"repository": "https://github.com/dimipay/pg-examination-server",
5+
"author": "kraccoon-dev <[email protected]>",
6+
"license": "MIT",
7+
"scripts": {
8+
"dev": "nodemon src/server.ts",
9+
"lint": "eslint src/**/*.ts"
10+
},
11+
"dependencies": {
12+
"dotenv": "^16.0.1",
13+
"express": "^4.18.1"
14+
},
15+
"devDependencies": {
16+
"@tsconfig/node16-strictest": "^1.0.3",
17+
"@types/express": "^4.17.13",
18+
"@types/node": "^18.7.2",
19+
"@typescript-eslint/eslint-plugin": "^5.33.0",
20+
"@typescript-eslint/parser": "^5.33.0",
21+
"eslint": "^8.21.0",
22+
"nodemon": "^2.0.19",
23+
"prettier": "^2.7.1",
24+
"ts-node": "^10.9.1",
25+
"typescript": "^4.7.4"
26+
}
27+
}

src/app.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import express from 'express'
2+
import config from './config'
3+
4+
import type { Application } from 'express'
5+
6+
export default class {
7+
public app: Application
8+
9+
constructor() {
10+
this.app = express()
11+
}
12+
13+
public listen(port = config.port): void {
14+
this.app.listen(port, () => {
15+
console.log(`Server is running on port ${port}`)
16+
})
17+
}
18+
}

src/config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'dotenv/config'
2+
3+
const check = (key: string, defaultValue?: string): string => {
4+
if (typeof process.env[key] === 'undefined') {
5+
if (typeof defaultValue === 'undefined') {
6+
throw new Error(`${key} is not defined in .env`)
7+
}
8+
return defaultValue
9+
}
10+
return process.env[key] as string
11+
}
12+
13+
export default {
14+
port: check('PORT', '3000'),
15+
}

src/server.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import App from './app'
2+
3+
const app = new App()
4+
5+
app.listen()

tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@tsconfig/node16-strictest/tsconfig.json"
3+
}

0 commit comments

Comments
 (0)