├── .env.example ├── .husky ├── .gitignore ├── pre-commit └── commit-msg ├── .nvmrc ├── .eslintignore ├── .lintstagedrc ├── src ├── math │ ├── add.ts │ └── add.test.ts ├── index.ts └── __tests__ │ └── math │ └── add.test.ts ├── tsconfig.prod.json ├── README.md ├── CONTRIBUTING.md ├── .prettierrc ├── nodemon.json ├── jest.config.js ├── .github └── workflows │ └── github-actions-demo.yml ├── .eslintrc.js ├── package.json ├── .gitignore └── tsconfig.json /.env.example: -------------------------------------------------------------------------------- 1 | MY_NAME= -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v14.15.4 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | coverage -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.(js|ts)": "eslint --fix" 3 | } -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint-staged && yarn test 5 | -------------------------------------------------------------------------------- /src/math/add.ts: -------------------------------------------------------------------------------- 1 | const add = (a: number, b: number): number => { 2 | return a + b; 3 | }; 4 | 5 | export default add; 6 | -------------------------------------------------------------------------------- /tsconfig.prod.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig", 3 | "exclude": ["src/__tests__/", "**/*.test.ts", "**/*.mock.ts"] 4 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) 2 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import dotenv from 'dotenv-safe'; 2 | import add from '@src/math/add'; 3 | 4 | dotenv.config(); 5 | 6 | console.log(process.env.MY_NAME); 7 | console.log(add(1, 3)); 8 | -------------------------------------------------------------------------------- /src/math/add.test.ts: -------------------------------------------------------------------------------- 1 | import add from '@src/math/add'; 2 | 3 | describe('This is a test', () => { 4 | it('should pass', () => { 5 | expect(add(1, 2)).toBe(3); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "printWidth": 120, 4 | "singleQuote": true, 5 | "trailingComma": "es5", 6 | "arrowParens": "avoid", 7 | "semi": true 8 | } 9 | -------------------------------------------------------------------------------- /src/__tests__/math/add.test.ts: -------------------------------------------------------------------------------- 1 | import add from '@src/math/add'; 2 | 3 | describe('This is a test', () => { 4 | it('should pass', () => { 5 | expect(add(1, 2)).toBe(3); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "ts,js,json", 4 | "ignore": ["node_modules", "coverage", "dist"], 5 | "exec": "ts-node -r tsconfig-paths/register ./src/index.ts", 6 | "restartable": "rs", 7 | "env": { 8 | "NODE_ENV": "development" 9 | } 10 | } -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if ! head -1 "$1" | grep -qE "^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?: .{1,}$"; then 3 | echo "Aborting commit. Your commit message is invalid." >&2 4 | exit 1 5 | fi 6 | if ! head -1 "$1" | grep -qE "^.{1,88}$"; then 7 | echo "Aborting commit. Your commit message is too long." >&2 8 | exit 1 9 | fi -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | coverageDirectory: 'coverage', 5 | collectCoverageFrom: ['src/**/*.{js,ts}'], 6 | coverageThreshold: { 7 | global: { 8 | branches: 0, 9 | functions: 0, 10 | lines: 0, 11 | statements: 0, 12 | }, 13 | }, 14 | moduleNameMapper: { 15 | 'src/(.*)': '/src/$1', 16 | }, 17 | moduleDirectories: ['node_modules', 'src'], 18 | testPathIgnorePatterns: ['/dist/', '/node_modules/'], 19 | }; 20 | -------------------------------------------------------------------------------- /.github/workflows/github-actions-demo.yml: -------------------------------------------------------------------------------- 1 | name: Explore github actions 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | jobs: 8 | Explore-GitHub-Actions: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." 12 | - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" 13 | - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." 14 | - name: Check out repository code 15 | uses: actions/checkout@v2 16 | - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." 17 | - run: echo "🖥️ The workflow is now ready to test your code on the runner." 18 | - name: List files in the repository 19 | run: | 20 | ls ${{ github.workspace }} 21 | - run: echo "🍏 This job's status is ${{ job.status }}. Congrats ${{ secrets.MY_NAME }}" 22 | Run-Unit-Tests: 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Check out repository code 26 | uses: actions/checkout@v2 27 | - name: Set up node 28 | uses: actions/setup-node@v1 29 | - name: Install dependencies 30 | run: npm install 31 | - name: Run tests 32 | run: npm test 33 | - run: echo "🍏 This job's status is ${{ job.status }}" 34 | 35 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | es2021: true, 4 | node: true, 5 | jest: true, 6 | }, 7 | extends: [ 8 | 'eslint:recommended', 9 | 'plugin:@typescript-eslint/recommended', 10 | 'airbnb-base', 11 | 'plugin:prettier/recommended', 12 | 'plugin:import/errors', 13 | 'plugin:import/warnings', 14 | 'plugin:import/typescript', 15 | ], 16 | parser: '@typescript-eslint/parser', 17 | parserOptions: { 18 | ecmaVersion: 12, 19 | sourceType: 'module', 20 | }, 21 | plugins: ['@typescript-eslint', 'prettier', 'import'], 22 | rules: { 23 | 'prettier/prettier': 'error', 24 | 'import/extensions': 'off', 25 | 'import/no-unresolved': 'error', 26 | 'no-console': 'off', 27 | 'import/order': [ 28 | 'error', 29 | { 30 | 'newlines-between': 'never', 31 | groups: [ 32 | ['builtin', 'external'], 33 | ['internal', 'parent', 'sibling', 'index'], 34 | ], 35 | }, 36 | ], 37 | }, 38 | settings: { 39 | 'import/parsers': { 40 | '@typescript-eslint/parser': ['.ts'], 41 | }, 42 | 'import/resolver': { 43 | typescript: { 44 | alwaysTryTypes: true, // always try to resolve types under `@types` directory even it doesn't contain any source code, like `@types/unist` 45 | 46 | // Choose from one of the "project" configs below or omit to use /tsconfig.json by default 47 | 48 | // use /path/to/folder/tsconfig.json 49 | project: './tsconfig.json', 50 | }, 51 | }, 52 | }, 53 | }; 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-ts-backend", 3 | "version": "1.0.0", 4 | "description": "Node.js and typescript backend setup project for blog-tube", 5 | "main": "index.js", 6 | "repository": "https://github.com/leoroese/blog-tube", 7 | "author": "Leonardo Roese", 8 | "license": "MIT", 9 | "scripts": { 10 | "start:dev": "nodemon", 11 | "start:prod": "node -r ts-node/register/transpile-only -r tsconfig-paths/register ./dist/src/index.js", 12 | "build": "tsc -p tsconfig.prod.json", 13 | "test": "jest", 14 | "test:watch": "jest --watch", 15 | "test:coverage": "jest --coverage", 16 | "prepare": "husky install", 17 | "lint": "eslint .", 18 | "lint:fix": "eslint --fix ." 19 | }, 20 | "devDependencies": { 21 | "@types/dotenv-safe": "^8.1.1", 22 | "@types/jest": "^26.0.20", 23 | "@types/node": "^14.14.33", 24 | "@typescript-eslint/eslint-plugin": "^4.17.0", 25 | "@typescript-eslint/parser": "^4.17.0", 26 | "commitizen": "^4.2.3", 27 | "cz-conventional-changelog": "3.3.0", 28 | "eslint": "^7.21.0", 29 | "eslint-config-airbnb-base": "^14.2.1", 30 | "eslint-config-prettier": "^8.1.0", 31 | "eslint-import-resolver-typescript": "^2.4.0", 32 | "eslint-plugin-import": "^2.22.1", 33 | "eslint-plugin-prettier": "^3.3.1", 34 | "husky": "^6.0.0", 35 | "jest": "^26.6.3", 36 | "lint-staged": "^10.5.4", 37 | "nodemon": "^2.0.7", 38 | "prettier": "^2.2.1", 39 | "ts-jest": "^26.5.3", 40 | "ts-node": "^9.1.1", 41 | "tsconfig-paths": "^3.9.0", 42 | "typescript": "^4.2.3" 43 | }, 44 | "dependencies": { 45 | "dotenv-safe": "^8.2.0" 46 | }, 47 | "config": { 48 | "commitizen": { 49 | "path": "./node_modules/cz-conventional-changelog" 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | >>>>>>> bc8fd8eb2c96f6e706ef3ac928942bc77b08a038 106 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Basic Options */ 6 | "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 7 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 8 | "lib": ["dom", "esnext"], /* Specify library files to be included in the compilation. */ 9 | "allowJs": true, /* Allow javascript files to be compiled. */ 10 | "outDir": "dist", /* Redirect output structure to the directory. */ 11 | "rootDir": ".", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 12 | "removeComments": true, /* Do not emit comments to output. */ 13 | /* Strict Type-Checking Options */ 14 | "strict": true, /* Enable all strict type-checking options. */ 15 | "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 16 | /* Module Resolution Options */ 17 | "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 18 | "baseUrl": ".", /* Base directory to resolve non-absolute module names. */ 19 | "paths": { /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 20 | "@src/*": ["src/*"] 21 | }, 22 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 23 | /* Experimental Options */ 24 | "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 25 | "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 26 | 27 | /* Advanced Options */ 28 | "skipLibCheck": true, /* Skip type checking of declaration files. */ 29 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 30 | }, 31 | "exclude": ["node_modules", "dist", "coverage"], 32 | "include": ["src"] 33 | } 34 | --------------------------------------------------------------------------------