Note: ensure you installed Node on your machine
On this page, we begin to initiate node.js (Typescript) with eslint, prettier, and ts-node-dev.
npm i typescript -g
npm i yarn -g
1# clone my repo
2git clone https://github.com/Adosh74/Node-Env
3
4# change directory to Node-Env
5cd Node-Env
6
7# install dependencies
8yarn
9
10# remove .git folder
11rm -rf .git
12
13## Now you can start project ✌
1 npm init -y
1# add dependencies.
2yarn add express typescript
3
4# add dev dependencies.
5yarn add @trivago/prettier-plugin-sort-imports prettier eslint @types/express @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-prettier ts-node ts-node-dev -D
tsconfig.json
1{
2 "compilerOptions": {
3 "target": "es2016",
4 "module": "commonjs",
5 "rootDir": "./src",
6 "outDir": "./dist",
7 "esModuleInterop": true,
8 "forceConsistentCasingInFileNames": true,
9 "strict": true,
10 "skipLibCheck": true
11 }
12}
13
1{
2 "trailingComma": "es5",
3 "useTabs": true,
4 "semi": true,
5 "singleQuote": true,
6 "quoteProps": "as-needed",
7 "importOrder": [
8 "^@core/(.*)$",
9 "^@server/(.*)$",
10 "^@ui/(.*)$",
11 "^[./]"
12 ],
13 "importOrderSeparation": true,
14 "importOrderSortSpecifiers": true,
15 "printWidth": 70
16}
.eslintrc.js
1module.exports = {
2 env: {
3 browser: true,
4 es2021: true,
5 node: true,
6 },
7 extends: [
8 'eslint:recommended',
9 'plugin:@typescript-eslint/recommended',
10 'prettier',
11 ],
12 overrides: [],
13 parser: '@typescript-eslint/parser',
14 parserOptions: {
15 ecmaVersion: 'latest',
16 sourceType: 'module',
17 },
18 plugins: ['@typescript-eslint', 'prettier'],
19 rules: {
20 'prettier/prettier': ['error', { endOfLine: 'auto' }],
21 'no-console': 0,
22 'no-var': 2,
23 'prefer-const': 'off',
24 },
25};