@onsever/create-express-ts-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +16 -0
- package/.eslintignore +146 -0
- package/.eslintrc.json +20 -0
- package/.prettierrc.json +8 -0
- package/README.md +36 -0
- package/bin/cli.js +94 -0
- package/jest.config.ts +195 -0
- package/package.json +69 -0
- package/src/configs/.gitkeep +0 -0
- package/src/controllers/.gitkeep +0 -0
- package/src/main.ts +17 -0
- package/src/middlewares/.gitkeep +0 -0
- package/src/models/.gitkeep +0 -0
- package/src/routes/.gitkeep +0 -0
- package/src/server.ts +47 -0
- package/src/services/.gitkeep +0 -0
- package/src/utils/.gitkeep +0 -0
- package/tests/example.test.ts +7 -0
- package/tsconfig.json +42 -0
package/.editorconfig
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
root = true
|
2
|
+
|
3
|
+
[*]
|
4
|
+
charset = utf-8
|
5
|
+
indent_style = space
|
6
|
+
indent_size = 2
|
7
|
+
end_of_line = lf
|
8
|
+
insert_final_newline = true
|
9
|
+
trim_trailing_whitespace = true
|
10
|
+
|
11
|
+
[*.{ts,js}]
|
12
|
+
quote_type = single
|
13
|
+
|
14
|
+
[*.md]
|
15
|
+
max_line_length = off
|
16
|
+
trim_trailing_whitespace = false
|
package/.eslintignore
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Created by https://www.toptal.com/developers/gitignore/api/node
|
2
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=node
|
3
|
+
|
4
|
+
### Node ###
|
5
|
+
# Logs
|
6
|
+
logs
|
7
|
+
*.log
|
8
|
+
npm-debug.log*
|
9
|
+
yarn-debug.log*
|
10
|
+
yarn-error.log*
|
11
|
+
lerna-debug.log*
|
12
|
+
.pnpm-debug.log*
|
13
|
+
|
14
|
+
build
|
15
|
+
|
16
|
+
# Diagnostic reports (https://nodejs.org/api/report.html)
|
17
|
+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
18
|
+
|
19
|
+
# Runtime data
|
20
|
+
pids
|
21
|
+
*.pid
|
22
|
+
*.seed
|
23
|
+
*.pid.lock
|
24
|
+
|
25
|
+
# Directory for instrumented libs generated by jscoverage/JSCover
|
26
|
+
lib-cov
|
27
|
+
|
28
|
+
# Coverage directory used by tools like istanbul
|
29
|
+
coverage
|
30
|
+
*.lcov
|
31
|
+
|
32
|
+
# nyc test coverage
|
33
|
+
.nyc_output
|
34
|
+
|
35
|
+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
36
|
+
.grunt
|
37
|
+
|
38
|
+
# Bower dependency directory (https://bower.io/)
|
39
|
+
bower_components
|
40
|
+
|
41
|
+
# node-waf configuration
|
42
|
+
.lock-wscript
|
43
|
+
|
44
|
+
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
45
|
+
build/Release
|
46
|
+
|
47
|
+
# Dependency directories
|
48
|
+
node_modules/
|
49
|
+
jspm_packages/
|
50
|
+
|
51
|
+
# Snowpack dependency directory (https://snowpack.dev/)
|
52
|
+
web_modules/
|
53
|
+
|
54
|
+
# TypeScript cache
|
55
|
+
*.tsbuildinfo
|
56
|
+
|
57
|
+
# Optional npm cache directory
|
58
|
+
.npm
|
59
|
+
|
60
|
+
# Optional eslint cache
|
61
|
+
.eslintcache
|
62
|
+
|
63
|
+
# Optional stylelint cache
|
64
|
+
.stylelintcache
|
65
|
+
|
66
|
+
# Microbundle cache
|
67
|
+
.rpt2_cache/
|
68
|
+
.rts2_cache_cjs/
|
69
|
+
.rts2_cache_es/
|
70
|
+
.rts2_cache_umd/
|
71
|
+
|
72
|
+
# Optional REPL history
|
73
|
+
.node_repl_history
|
74
|
+
|
75
|
+
# Output of 'npm pack'
|
76
|
+
*.tgz
|
77
|
+
|
78
|
+
# Yarn Integrity file
|
79
|
+
.yarn-integrity
|
80
|
+
|
81
|
+
# dotenv environment variable files
|
82
|
+
.env
|
83
|
+
.env.development.local
|
84
|
+
.env.test.local
|
85
|
+
.env.production.local
|
86
|
+
.env.local
|
87
|
+
|
88
|
+
# parcel-bundler cache (https://parceljs.org/)
|
89
|
+
.cache
|
90
|
+
.parcel-cache
|
91
|
+
|
92
|
+
# Next.js build output
|
93
|
+
.next
|
94
|
+
out
|
95
|
+
|
96
|
+
# Nuxt.js build / generate output
|
97
|
+
.nuxt
|
98
|
+
dist
|
99
|
+
|
100
|
+
# Gatsby files
|
101
|
+
.cache/
|
102
|
+
# Comment in the public line in if your project uses Gatsby and not Next.js
|
103
|
+
# https://nextjs.org/blog/next-9-1#public-directory-support
|
104
|
+
# public
|
105
|
+
|
106
|
+
# vuepress build output
|
107
|
+
.vuepress/dist
|
108
|
+
|
109
|
+
# vuepress v2.x temp and cache directory
|
110
|
+
.temp
|
111
|
+
|
112
|
+
# Docusaurus cache and generated files
|
113
|
+
.docusaurus
|
114
|
+
|
115
|
+
# Serverless directories
|
116
|
+
.serverless/
|
117
|
+
|
118
|
+
# FuseBox cache
|
119
|
+
.fusebox/
|
120
|
+
|
121
|
+
# DynamoDB Local files
|
122
|
+
.dynamodb/
|
123
|
+
|
124
|
+
# TernJS port file
|
125
|
+
.tern-port
|
126
|
+
|
127
|
+
# Stores VSCode versions used for testing VSCode extensions
|
128
|
+
.vscode-test
|
129
|
+
|
130
|
+
# yarn v2
|
131
|
+
.yarn/cache
|
132
|
+
.yarn/unplugged
|
133
|
+
.yarn/build-state.yml
|
134
|
+
.yarn/install-state.gz
|
135
|
+
.pnp.*
|
136
|
+
|
137
|
+
### Node Patch ###
|
138
|
+
# Serverless Webpack directories
|
139
|
+
.webpack/
|
140
|
+
|
141
|
+
# Optional stylelint cache
|
142
|
+
|
143
|
+
# SvelteKit build / generate output
|
144
|
+
.svelte-kit
|
145
|
+
|
146
|
+
# End of https://www.toptal.com/developers/gitignore/api/node
|
package/.eslintrc.json
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"root": true,
|
3
|
+
"parser": "@typescript-eslint/parser",
|
4
|
+
"plugins": ["@typescript-eslint"],
|
5
|
+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
|
6
|
+
"parserOptions": {
|
7
|
+
"ecmaVersion": 2020, // Allows for the parsing of modern ECMAScript features
|
8
|
+
"sourceType": "module" // Allows for the use of imports
|
9
|
+
},
|
10
|
+
"rules": {
|
11
|
+
"semi": [2, "always"],
|
12
|
+
"space-before-function-paren": [0, { "anonymous": "always", "named": "always" }],
|
13
|
+
"camelcase": 0,
|
14
|
+
"no-return-assign": 0,
|
15
|
+
"quotes": ["error", "single"],
|
16
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
17
|
+
"@typescript-eslint/no-namespace": "off",
|
18
|
+
"@typescript-eslint/explicit-module-boundary-types": "off"
|
19
|
+
}
|
20
|
+
}
|
package/.prettierrc.json
ADDED
package/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Create Express Application with TypeScript
|
2
|
+
|
3
|
+
This is a starter template for [Express](https://expressjs.com/) web framework for [Node.js](https://nodejs.org/en/) using [TypeScript](https://www.typescriptlang.org/).
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- TypeScript support with absolute imports and path aliases
|
8
|
+
- Live reload with [nodemon](https://nodemon.io/)
|
9
|
+
- Testing support with [Jest](https://jestjs.io/)
|
10
|
+
- Formatting support with [Prettier](https://prettier.io/)
|
11
|
+
- Linting support with [ESLint](https://eslint.org/)
|
12
|
+
- Logging support with [Pino](https://getpino.io/)
|
13
|
+
|
14
|
+
## Getting Started
|
15
|
+
|
16
|
+
Please make sure you have [pnpm](https://pnpm.io/) installed.
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
To use this template, run the following command:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
npx @onsever/create-express-ts-app <project-name>
|
24
|
+
```
|
25
|
+
|
26
|
+
## Commands
|
27
|
+
|
28
|
+
- `pnpm build` - Build the project
|
29
|
+
- `pnpm start` - Start the server in production mode
|
30
|
+
- `pnpm dev` - Start the server in development mode with live reload
|
31
|
+
- `pnpm lint:check` - Check for linting errors
|
32
|
+
- `pnpm lint:fix` - Fix linting errors
|
33
|
+
- `pnpm prettier:check` - Check for formatting errors
|
34
|
+
- `pnpm prettier:fix` - Fix formatting errors
|
35
|
+
- `pnpm test` - Run tests
|
36
|
+
- `pnpm test:watch` - Run tests in watch mode
|
package/bin/cli.js
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
const { execSync } = require('child_process');
|
3
|
+
const fs = require('fs');
|
4
|
+
const path = require('path');
|
5
|
+
|
6
|
+
const runCommand = (command) => {
|
7
|
+
try {
|
8
|
+
execSync(`${command}`, { stdio: 'inherit' });
|
9
|
+
} catch (e) {
|
10
|
+
console.error(`Failed to execute ${command}`, e);
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
|
14
|
+
return true;
|
15
|
+
};
|
16
|
+
|
17
|
+
const projectName = process.argv[2];
|
18
|
+
|
19
|
+
if (!projectName) {
|
20
|
+
console.error('Please specify a project name.');
|
21
|
+
process.exit(1);
|
22
|
+
}
|
23
|
+
|
24
|
+
console.log(`Creating a new Express application with name ${projectName}...`);
|
25
|
+
|
26
|
+
const gitCheckoutCommand = `git clone --depth 1 https://github.com/onsever/create-express-ts-app ${projectName}`;
|
27
|
+
const installDepsCommand = `cd ${projectName} && pnpm install`;
|
28
|
+
|
29
|
+
const checkedOut = runCommand(gitCheckoutCommand);
|
30
|
+
if (!checkedOut) process.exit(1);
|
31
|
+
|
32
|
+
console.log(`Installing dependencies for ${projectName}...`);
|
33
|
+
|
34
|
+
const installedDeps = runCommand(installDepsCommand);
|
35
|
+
if (!installedDeps) process.exit(1);
|
36
|
+
|
37
|
+
const packageJsonPath = `${projectName}/package.json`;
|
38
|
+
try {
|
39
|
+
const packageJsonData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
40
|
+
|
41
|
+
packageJsonData.name = projectName;
|
42
|
+
packageJsonData.version = '1.0.0';
|
43
|
+
packageJsonData.description = 'This project was bootstrapped with Create Express TS Starter';
|
44
|
+
delete packageJsonData.bin;
|
45
|
+
delete packageJsonData.repository;
|
46
|
+
delete packageJsonData.author;
|
47
|
+
delete packageJsonData.license;
|
48
|
+
delete packageJsonData.keywords;
|
49
|
+
|
50
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJsonData, null, 2));
|
51
|
+
} catch (err) {
|
52
|
+
console.error(`Failed to modify package.json: ${err.message}`);
|
53
|
+
process.exit(1);
|
54
|
+
}
|
55
|
+
console.log(`Removing the local Git repository...`);
|
56
|
+
|
57
|
+
const removeGitRepoCommand = `rm -rf ${projectName}/.git`;
|
58
|
+
const gitRepoRemoved = runCommand(removeGitRepoCommand);
|
59
|
+
if (!gitRepoRemoved) process.exit(1);
|
60
|
+
|
61
|
+
console.log(`Initializing a new Git repository for ${projectName}...`);
|
62
|
+
|
63
|
+
const createGitRepoCommand = `cd ${projectName} && git init`;
|
64
|
+
const gitRepoCreated = runCommand(createGitRepoCommand);
|
65
|
+
if (!gitRepoCreated) process.exit(1);
|
66
|
+
|
67
|
+
console.log(`Clearing the folders...`);
|
68
|
+
|
69
|
+
removeGitKeepsSync(path.join(__dirname, './src'));
|
70
|
+
|
71
|
+
console.log(`Congratulations! ${projectName} is ready to go!`);
|
72
|
+
console.log(`cd ${projectName} && pnpm dev`);
|
73
|
+
|
74
|
+
function removeGitKeepsSync(directory) {
|
75
|
+
try {
|
76
|
+
const files = fs.readdirSync(directory);
|
77
|
+
|
78
|
+
files.forEach((file) => {
|
79
|
+
const filePath = path.join(directory, file);
|
80
|
+
|
81
|
+
const stat = fs.statSync(filePath);
|
82
|
+
|
83
|
+
if (stat.isDirectory()) {
|
84
|
+
const gitKeepPath = path.join(filePath, '.gitkeep');
|
85
|
+
if (fs.existsSync(gitKeepPath)) {
|
86
|
+
fs.unlinkSync(gitKeepPath);
|
87
|
+
}
|
88
|
+
removeGitKeepsSync(filePath);
|
89
|
+
}
|
90
|
+
});
|
91
|
+
} catch (err) {
|
92
|
+
console.error(`Error: ${err.message}`);
|
93
|
+
}
|
94
|
+
}
|
package/jest.config.ts
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
/*
|
2
|
+
* For a detailed explanation regarding each configuration property and type check, visit:
|
3
|
+
* https://jestjs.io/docs/configuration
|
4
|
+
*/
|
5
|
+
|
6
|
+
export default {
|
7
|
+
// All imported modules in your tests should be mocked automatically
|
8
|
+
// automock: false,
|
9
|
+
|
10
|
+
// Stop running tests after `n` failures
|
11
|
+
// bail: 0,
|
12
|
+
|
13
|
+
// The directory where Jest should store its cached dependency information
|
14
|
+
// cacheDirectory: "/private/var/folders/vl/2cwdjbls4r71z3y_nm_2jtq80000gn/T/jest_dx",
|
15
|
+
|
16
|
+
// Automatically clear mock calls, instances, contexts and results before every tests
|
17
|
+
clearMocks: true,
|
18
|
+
|
19
|
+
// Indicates whether the coverage information should be collected while executing the tests
|
20
|
+
collectCoverage: true,
|
21
|
+
|
22
|
+
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
23
|
+
// collectCoverageFrom: undefined,
|
24
|
+
|
25
|
+
// The directory where Jest should output its coverage files
|
26
|
+
coverageDirectory: 'coverage',
|
27
|
+
|
28
|
+
// An array of regexp pattern strings used to skip coverage collection
|
29
|
+
// coveragePathIgnorePatterns: [
|
30
|
+
// "/node_modules/"
|
31
|
+
// ],
|
32
|
+
|
33
|
+
// Indicates which provider should be used to instrument code for coverage
|
34
|
+
coverageProvider: 'v8'
|
35
|
+
|
36
|
+
// A list of reporter names that Jest uses when writing coverage reports
|
37
|
+
// coverageReporters: [
|
38
|
+
// "json",
|
39
|
+
// "text",
|
40
|
+
// "lcov",
|
41
|
+
// "clover"
|
42
|
+
// ],
|
43
|
+
|
44
|
+
// An object that configures minimum threshold enforcement for coverage results
|
45
|
+
// coverageThreshold: undefined,
|
46
|
+
|
47
|
+
// A path to a custom dependency extractor
|
48
|
+
// dependencyExtractor: undefined,
|
49
|
+
|
50
|
+
// Make calling deprecated APIs throw helpful error messages
|
51
|
+
// errorOnDeprecated: false,
|
52
|
+
|
53
|
+
// The default configuration for fake timers
|
54
|
+
// fakeTimers: {
|
55
|
+
// "enableGlobally": false
|
56
|
+
// },
|
57
|
+
|
58
|
+
// Force coverage collection from ignored files using an array of glob patterns
|
59
|
+
// forceCoverageMatch: [],
|
60
|
+
|
61
|
+
// A path to a module which exports an async function that is triggered once before all tests suites
|
62
|
+
// globalSetup: undefined,
|
63
|
+
|
64
|
+
// A path to a module which exports an async function that is triggered once after all tests suites
|
65
|
+
// globalTeardown: undefined,
|
66
|
+
|
67
|
+
// A set of global variables that need to be available in all tests environments
|
68
|
+
// globals: {},
|
69
|
+
|
70
|
+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
71
|
+
// maxWorkers: "50%",
|
72
|
+
|
73
|
+
// An array of directory names to be searched recursively up from the requiring module's location
|
74
|
+
// moduleDirectories: [
|
75
|
+
// "node_modules"
|
76
|
+
// ],
|
77
|
+
|
78
|
+
// An array of file extensions your modules use
|
79
|
+
// moduleFileExtensions: [
|
80
|
+
// "js",
|
81
|
+
// "mjs",
|
82
|
+
// "cjs",
|
83
|
+
// "jsx",
|
84
|
+
// "ts",
|
85
|
+
// "tsx",
|
86
|
+
// "json",
|
87
|
+
// "node"
|
88
|
+
// ],
|
89
|
+
|
90
|
+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
91
|
+
// moduleNameMapper: {},
|
92
|
+
|
93
|
+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
94
|
+
// modulePathIgnorePatterns: [],
|
95
|
+
|
96
|
+
// Activates notifications for tests results
|
97
|
+
// notify: false,
|
98
|
+
|
99
|
+
// An enum that specifies notification mode. Requires { notify: true }
|
100
|
+
// notifyMode: "failure-change",
|
101
|
+
|
102
|
+
// A preset that is used as a base for Jest's configuration
|
103
|
+
// preset: undefined,
|
104
|
+
|
105
|
+
// Run tests from one or more projects
|
106
|
+
// projects: undefined,
|
107
|
+
|
108
|
+
// Use this configuration option to add custom reporters to Jest
|
109
|
+
// reporters: undefined,
|
110
|
+
|
111
|
+
// Automatically reset mock state before every tests
|
112
|
+
// resetMocks: false,
|
113
|
+
|
114
|
+
// Reset the module registry before running each individual tests
|
115
|
+
// resetModules: false,
|
116
|
+
|
117
|
+
// A path to a custom resolver
|
118
|
+
// resolver: undefined,
|
119
|
+
|
120
|
+
// Automatically restore mock state and implementation before every tests
|
121
|
+
// restoreMocks: false,
|
122
|
+
|
123
|
+
// The root directory that Jest should scan for tests and modules within
|
124
|
+
// rootDir: undefined,
|
125
|
+
|
126
|
+
// A list of paths to directories that Jest should use to search for files in
|
127
|
+
// roots: [
|
128
|
+
// "<rootDir>"
|
129
|
+
// ],
|
130
|
+
|
131
|
+
// Allows you to use a custom runner instead of Jest's default tests runner
|
132
|
+
// runner: "jest-runner",
|
133
|
+
|
134
|
+
// The paths to modules that run some code to configure or set up the testing environment before each tests
|
135
|
+
// setupFiles: [],
|
136
|
+
|
137
|
+
// A list of paths to modules that run some code to configure or set up the testing framework before each tests
|
138
|
+
// setupFilesAfterEnv: [],
|
139
|
+
|
140
|
+
// The number of seconds after which a tests is considered as slow and reported as such in the results.
|
141
|
+
// slowTestThreshold: 5,
|
142
|
+
|
143
|
+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
144
|
+
// snapshotSerializers: [],
|
145
|
+
|
146
|
+
// The tests environment that will be used for testing
|
147
|
+
// testEnvironment: "jest-environment-node",
|
148
|
+
|
149
|
+
// Options that will be passed to the testEnvironment
|
150
|
+
// testEnvironmentOptions: {},
|
151
|
+
|
152
|
+
// Adds a location field to tests results
|
153
|
+
// testLocationInResults: false,
|
154
|
+
|
155
|
+
// The glob patterns Jest uses to detect tests files
|
156
|
+
// testMatch: [
|
157
|
+
// "**/__tests__/**/*.[jt]s?(x)",
|
158
|
+
// "**/?(*.)+(spec|tests).[tj]s?(x)"
|
159
|
+
// ],
|
160
|
+
|
161
|
+
// An array of regexp pattern strings that are matched against all tests paths, matched tests are skipped
|
162
|
+
// testPathIgnorePatterns: [
|
163
|
+
// "/node_modules/"
|
164
|
+
// ],
|
165
|
+
|
166
|
+
// The regexp pattern or array of patterns that Jest uses to detect tests files
|
167
|
+
// testRegex: [],
|
168
|
+
|
169
|
+
// This option allows the use of a custom results processor
|
170
|
+
// testResultsProcessor: undefined,
|
171
|
+
|
172
|
+
// This option allows use of a custom tests runner
|
173
|
+
// testRunner: "jest-circus/runner",
|
174
|
+
|
175
|
+
// A map from regular expressions to paths to transformers
|
176
|
+
// transform: undefined,
|
177
|
+
|
178
|
+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
179
|
+
// transformIgnorePatterns: [
|
180
|
+
// "/node_modules/",
|
181
|
+
// "\\.pnp\\.[^\\/]+$"
|
182
|
+
// ],
|
183
|
+
|
184
|
+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
185
|
+
// unmockedModulePathPatterns: undefined,
|
186
|
+
|
187
|
+
// Indicates whether each individual tests should be reported during the run
|
188
|
+
// verbose: undefined,
|
189
|
+
|
190
|
+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
191
|
+
// watchPathIgnorePatterns: [],
|
192
|
+
|
193
|
+
// Whether to use watchman for file crawling
|
194
|
+
// watchman: true,
|
195
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
{
|
2
|
+
"name": "@onsever/create-express-ts-app",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "This is a starter template for Express.js with TypeScript that includes Jest, Prettier, ESLint, and more.",
|
5
|
+
"bin": "./bin/cli.js",
|
6
|
+
"main": "main.js",
|
7
|
+
"scripts": {
|
8
|
+
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
|
9
|
+
"start": "nodemon ./build/main.js",
|
10
|
+
"dev": "nodemon -r tsconfig-paths/register src/main.ts | pino-pretty",
|
11
|
+
"lint:check": "eslint ''src/**/*.ts",
|
12
|
+
"lint:fix": "eslint 'src/**/*.ts' --fix",
|
13
|
+
"prettier:check": "prettier --check 'src/**/*.{ts,json}'",
|
14
|
+
"prettier:fix": "prettier --write 'src/**/*.{ts,json}'",
|
15
|
+
"test": "jest --config jest.config.ts",
|
16
|
+
"test:watch": "jest --watchAll --config jest.config.ts --collectCoverage=false"
|
17
|
+
},
|
18
|
+
"repository": {
|
19
|
+
"type": "git",
|
20
|
+
"url": "https://github.com/onsever/create-express-ts-app"
|
21
|
+
},
|
22
|
+
"keywords": [
|
23
|
+
"nodejs",
|
24
|
+
"express",
|
25
|
+
"typescript"
|
26
|
+
],
|
27
|
+
"author": "Onurcan Sever",
|
28
|
+
"license": "MIT",
|
29
|
+
"devDependencies": {
|
30
|
+
"@jest/types": "^29.6.3",
|
31
|
+
"@types/compression": "^1.7.3",
|
32
|
+
"@types/cookie-session": "^2.0.45",
|
33
|
+
"@types/cors": "^2.8.14",
|
34
|
+
"@types/express": "^4.17.17",
|
35
|
+
"@types/hpp": "^0.2.2",
|
36
|
+
"@types/jest": "^29.5.4",
|
37
|
+
"@types/morgan": "^1.9.5",
|
38
|
+
"@types/node": "^20.6.0",
|
39
|
+
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
40
|
+
"@typescript-eslint/parser": "^6.6.0",
|
41
|
+
"dotenv": "^16.3.1",
|
42
|
+
"eslint": "^8.49.0",
|
43
|
+
"eslint-config-prettier": "^9.0.0",
|
44
|
+
"eslint-plugin-prettier": "^5.0.0",
|
45
|
+
"jest": "^29.6.4",
|
46
|
+
"nodemon": "^3.0.1",
|
47
|
+
"pino": "^8.15.1",
|
48
|
+
"pino-pretty": "^10.2.0",
|
49
|
+
"prettier": "^3.0.3",
|
50
|
+
"ts-jest": "^29.1.1",
|
51
|
+
"ts-node": "^10.9.1",
|
52
|
+
"tsc-alias": "^1.8.7",
|
53
|
+
"tsc-watch": "^6.0.4",
|
54
|
+
"tsconfig-paths": "^4.2.0",
|
55
|
+
"typescript": "^5.2.2",
|
56
|
+
"typescript-transform-paths": "^3.4.6"
|
57
|
+
},
|
58
|
+
"dependencies": {
|
59
|
+
"compression": "^1.7.4",
|
60
|
+
"cookie-session": "^2.0.0",
|
61
|
+
"cors": "^2.8.5",
|
62
|
+
"express": "^4.18.2",
|
63
|
+
"express-async-errors": "^3.1.1",
|
64
|
+
"helmet": "^7.0.0",
|
65
|
+
"hpp": "^0.2.3",
|
66
|
+
"http-status-codes": "^2.2.0",
|
67
|
+
"morgan": "^1.10.0"
|
68
|
+
}
|
69
|
+
}
|
File without changes
|
File without changes
|
package/src/main.ts
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
import server from '@root/server';
|
2
|
+
import pino from 'pino';
|
3
|
+
|
4
|
+
const logger = pino({
|
5
|
+
level: 'info'
|
6
|
+
});
|
7
|
+
|
8
|
+
const PORT: number = Number(process.env.PORT) || 3000;
|
9
|
+
const HOSTNAME: string = process.env.HOSTNAME || 'localhost';
|
10
|
+
|
11
|
+
server
|
12
|
+
.listen(PORT, HOSTNAME, () => {
|
13
|
+
logger.info(`Example app listening on port ${PORT}!`);
|
14
|
+
})
|
15
|
+
.on('error', (err: Error) => {
|
16
|
+
logger.error(err);
|
17
|
+
});
|
File without changes
|
File without changes
|
File without changes
|
package/src/server.ts
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
import express, { json, urlencoded } from 'express';
|
2
|
+
import { createServer } from 'http';
|
3
|
+
import hpp from 'hpp';
|
4
|
+
import helmet from 'helmet';
|
5
|
+
import cors from 'cors';
|
6
|
+
import compression from 'compression';
|
7
|
+
import cookieSession from 'cookie-session';
|
8
|
+
import morgan from 'morgan';
|
9
|
+
import dotenv from 'dotenv';
|
10
|
+
|
11
|
+
dotenv.config({});
|
12
|
+
|
13
|
+
const app = express();
|
14
|
+
|
15
|
+
app.use(morgan('dev'));
|
16
|
+
app.use(
|
17
|
+
cookieSession({
|
18
|
+
name: 'session',
|
19
|
+
keys: ['key1', 'key2'],
|
20
|
+
maxAge: 24 * 60 * 60 * 1000, // 24 hours
|
21
|
+
secure: false
|
22
|
+
})
|
23
|
+
);
|
24
|
+
app.use(hpp());
|
25
|
+
app.use(helmet());
|
26
|
+
app.use(
|
27
|
+
cors({
|
28
|
+
origin: '*',
|
29
|
+
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
|
30
|
+
allowedHeaders: ['Content-Type', 'Authorization']
|
31
|
+
})
|
32
|
+
);
|
33
|
+
app.use(compression());
|
34
|
+
app.use(
|
35
|
+
json({
|
36
|
+
limit: '50mb'
|
37
|
+
})
|
38
|
+
);
|
39
|
+
app.use(urlencoded({ extended: true, limit: '50mb' }));
|
40
|
+
|
41
|
+
app.get('/', (req, res) => {
|
42
|
+
res.send('Hello World!');
|
43
|
+
});
|
44
|
+
|
45
|
+
const server = createServer(app);
|
46
|
+
|
47
|
+
export default server;
|
File without changes
|
File without changes
|
package/tsconfig.json
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "ES2016",
|
4
|
+
"module": "commonjs",
|
5
|
+
"lib": ["DOM", "ES2016"],
|
6
|
+
"baseUrl": ".",
|
7
|
+
"outDir": "./build",
|
8
|
+
"rootDir": "src",
|
9
|
+
"strict": true,
|
10
|
+
"noImplicitAny": true,
|
11
|
+
"noUnusedLocals": false,
|
12
|
+
"noUnusedParameters": false,
|
13
|
+
"moduleResolution": "node",
|
14
|
+
"esModuleInterop": true,
|
15
|
+
"sourceMap": true,
|
16
|
+
"experimentalDecorators": true,
|
17
|
+
"emitDecoratorMetadata": true,
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
19
|
+
"allowSyntheticDefaultImports": true,
|
20
|
+
"pretty": true,
|
21
|
+
"resolveJsonModule": true,
|
22
|
+
"plugins": [
|
23
|
+
{
|
24
|
+
"transform": "typescript-transform-paths"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"transform": "typescript-transform-paths",
|
28
|
+
"afterDeclarations": true
|
29
|
+
}
|
30
|
+
],
|
31
|
+
"paths": {
|
32
|
+
"@configs/*": ["./src/config/*"],
|
33
|
+
"@controllers/*": ["./src/controllers/*"],
|
34
|
+
"@middlewares/*": ["./src/middlewares/*"],
|
35
|
+
"@models/*": ["./src/models/*"],
|
36
|
+
"@routes/*": ["./src/routes/*"],
|
37
|
+
"@services/*": ["./src/services/*"],
|
38
|
+
"@utils/*": ["./src/utils/*"],
|
39
|
+
"@root/*": ["./src/*"]
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|