eslint: Main linter (error checker).
prettier: Primary code formatter.
eslint-config-prettier: ESLint configuration to avoid conflicts with Prettier.
eslint-plugin-prettier: Adds some Prettier rules to ESLint.
@typescript-eslint/eslint-plugin: ESLint plugin providing rules for TypeScript.
@typescript-eslint/parser: Parser allowing ESLint to check TypeScript errors.
ts-node: Used to run TypeScript code directly without needing to build.
tsc-alias: Handles aliases during build.
tsconfig-paths: When setting alias imports in a project using ts-node, we need tsconfig-paths to understand the paths and baseUrl in the tsconfig.json file.
rimraf: Used to remove the 'dist' folder before building.
nodemon: Used to automatically restart the server when changes occur in the code.
File tsconfig.json
{
"compilerOptions": {
"module": "CommonJS", //Specifies the output module system used.
"moduleResolution": "node", // Determines how module resolution is performed.
"target": "ES2020", // Specifies the ECMAScript target version for the emitted code.
"outDir": "dist", // Specifies the output directory for compiled files.
"esModuleInterop": true /* Emit additional JavaScript to enable importing CommonJS modules easily. This facilitates 'allowSyntheticDefaultImports' for type compatibility. */,
"strict": true /* Enables all strict type-checking options. */,
"skipLibCheck": true /* Skips type checking of declaration files (.d.ts). */,
"baseUrl": ".", // Base directory to resolve non-relative module names.
"paths": {
"~/*": ["src/*"] // Relative paths for imports (aliases).
}
},
"ts-node": {
"require": ["tsconfig-paths/register"]
},
"files": ["src/type.d.ts"], // Files used to define global types for the project.
"include": ["src/**/*"] // Specifies paths included for compilation.
}
Access this link find with keyword "nodejs", copy and paste all content to this file.
nodemon.json
{
"watch": ["src"], // Monitors changes in the 'src' directory.
"ext": ".ts,.js", // Tracks files with '.ts' and '.js' extensions.
"ignore": [], // Lists files to ignore tracking changes.
"exec": "npx ts-node ./src/index.ts" // Executes the 'index.ts' file using ts-node.
}
package.json
Change scripts in file package.json to
"scripts": {
"dev": "npx nodemon", // Used for development to auto-reload changes while coding.
"build": "rimraf ./dist && tsc && tsc-alias", // Compiles and builds the project into the 'dist' directory after cleaning it, also handles TypeScript aliases.
"start": "node dist/index.js", // Executes the built code, must be built beforehand.
"lint": "eslint .", // Checks for code style and potential errors.
"lint:fix": "eslint . --fix", // Fixes linting errors automatically.
"prettier": "prettier --check .", // Checks code formatting using Prettier.
"prettier:fix": "prettier --write ." // Automatically fixes code formatting using Prettier.
}
Create type.d.ts
Create src folder, then create file type.d.ts
type.d.ts is a file that helps you define the data types of variables while coding ts
This ticket has not been finished yet. So I reopen it
Please change your status before restart
Leader please help assign the member implement this ticket
cc @quyn2904
ESlint + Prettier
eslint: Main linter (error checker). prettier: Primary code formatter. eslint-config-prettier: ESLint configuration to avoid conflicts with Prettier. eslint-plugin-prettier: Adds some Prettier rules to ESLint. @typescript-eslint/eslint-plugin: ESLint plugin providing rules for TypeScript. @typescript-eslint/parser: Parser allowing ESLint to check TypeScript errors. ts-node: Used to run TypeScript code directly without needing to build. tsc-alias: Handles aliases during build. tsconfig-paths: When setting alias imports in a project using ts-node, we need tsconfig-paths to understand the paths and baseUrl in the tsconfig.json file. rimraf: Used to remove the 'dist' folder before building. nodemon: Used to automatically restart the server when changes occur in the code.
File tsconfig.json
File .eslintrc
File .eslintignore
Loại bỏ những file không muốn format code
File .prettierrc
File .prettierignore
Không canh lề cho những cái mình không thích
File .editorconfig
Install extensions EditorConfig for VS Code
File .gitignore
Avoid pushing unnecessary files to github
Access this link find with keyword "nodejs", copy and paste all content to this file.
nodemon.json
package.json
Change
scripts
in file package.json toCreate type.d.ts
Create
src
folder, then create filetype.d.ts
type.d.ts is a file that helps you define the data types of variables while coding ts