{"id":19454468,"url":"https://github.com/codemaster17/express-ts-backend-production-setup","last_synced_at":"2025-10-13T20:02:16.940Z","repository":{"id":255223785,"uuid":"848917741","full_name":"CodeMaster17/express-ts-backend-production-setup","owner":"CodeMaster17","description":"Step by step process to setup production setup for backend in express js and typescript","archived":false,"fork":false,"pushed_at":"2024-11-03T07:48:05.000Z","size":554,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T10:25:40.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeMaster17.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-28T16:37:12.000Z","updated_at":"2024-11-03T07:48:08.000Z","dependencies_parsed_at":"2024-08-28T18:29:01.440Z","dependency_job_id":"b30c4f77-02aa-497b-b735-f05487c1a32c","html_url":"https://github.com/CodeMaster17/express-ts-backend-production-setup","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"2e1e82ac5db5ff01d0de5c12b2ac825b6058aaa2"},"previous_names":["codemaster17/express-ts-backend-production-setup"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CodeMaster17/express-ts-backend-production-setup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMaster17%2Fexpress-ts-backend-production-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMaster17%2Fexpress-ts-backend-production-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMaster17%2Fexpress-ts-backend-production-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMaster17%2Fexpress-ts-backend-production-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeMaster17","download_url":"https://codeload.github.com/CodeMaster17/express-ts-backend-production-setup/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeMaster17%2Fexpress-ts-backend-production-setup/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279016822,"owners_count":26085890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T17:09:49.396Z","updated_at":"2025-10-13T20:02:16.906Z","avatar_url":"https://github.com/CodeMaster17.png","language":"TypeScript","readme":"# This repo step by step explains how to start with nodejs production setup\n\n## This setup is based upon MVC architecture.\n\nMVC architecture is a software design pattern for developing web applications. It is made up of three parts: Model, View, and Controller.\n\n## Initial setup\n\n1. Initialize the repo\n\n```\nnpm init -y\n```\n\n2. Install express\n\n```\nnpm install express\n```\n\n3. Create `.gitignore` file and add node_modules\n\n4. Create `index.js` file, and write any `console.log` to check for output\n\n5. Update the scripts in `package.json`\n\n    ```\n     \"scripts\": {\n         \"start\": \"node index.js\"\n    },\n    ```\n\n## Husky setup\n\n1. Install `husky` and `lint-staged` as devDependencies\n\n    ```\n    npm i husky lint-staged -D\n    ```\n\n2. Initialize `husky`\n\n    ```\n    npx husky init\n    ```\n\n=\u003e A `.husky` folder would be created\n\n## Typescript setup\n\n1. Install typescript\n\n    Installing it as devDependencies because we don't need it in production\n\n    ```\n    npm i typescript -D\n    ```\n\n2. Setting up `tsconfig.json` file\n\n    ```\n    npx tsc --init\n    ```\n\n    A tsconfig.json file would be created\n\n3. Update the `tsconfig.json` file\n\n    ```\n    {\n        \"compilerOptions\": {\n            \"target\": \"es6\",\n            \"module\": \"commonjs\",\n            \"outDir\": \"./dist\",\n            \"rootDir\": \"./src\",\n            \"strict\": true,\n            \"esModuleInterop\": true,\n            \"alwaysStrict\": true,\n            \"strictPropertyInitialization\": true,\n            \"strictNullChecks\": true,\n            \"strictFunctionTypes\": true,\n            \"noUnusedLocals\": true,\n            \"noUnusedParameters\": true,\n            \"noImplicitReturns\": true,\n            \"forceConsistentCasingInFileNames\": true,\n        }\n    }\n    ```\n\n4. Install `ts-node` and `@types/node`\n\n    ```\n    npm i ts-node @types/node -D\n    ```\n\n==\u003e Delete the `index.js` file and create `index.ts` file inside `src` folder\n\n5. Install `nodemon` as dev dependency\n\n    ```\n    npm i nodemon -D\n    ```\n\n6. Update the scripts in `package.json`\n\n    ```\n    \"scripts\": {\n        \"start\": \"node dist/index.js\",\n        \"dev\": \"nodemon src/index.ts\",\n        \"build\": \"npx tsc\"\n    },\n    ```\n\n7. Update .gitignore file\n\n    ```\n    dist\n    ```\n\n## Setting up folder structure\n\n![Alt text](image.png)\n\n## Commitlint setup\n\n1. Install `@commitlint/cli` and `@commitlint/config-conventional` as devDependencies\n\n    ```\n    npm i @commitlint/cli @commitlint/config-conventional -D\n    ```\n\n2. Create `commitlint.config.js` file\n\n    ```\n    // commitlint.config.js\n\n    module.exports = {\n       extends: ['@commitlint/cli', '@commitlint/config-conventional'],\n       rules: {\n          'type-enum': [\n                2, // level: error\n                'always', // applicable condition\n                [\n                   'feat',    // New feature\n                   'fix',     // Bug fix\n                   'docs',    // Documentation changes\n                   'style',   // Code style changes (formatting, missing semi colons, etc.)\n                   'refactor',// Code refactoring (neither fixes a bug nor adds a feature)\n                   'perf',    // Performance improvements\n                   'test',    // Adding missing tests or correcting existing tests\n                   'build',   // Changes affecting the build system or external dependencies\n                   'ci',      // Changes to CI configuration files and scripts\n                   'chore',   // Other changes that don’t modify src or test files\n                   'revert'   // Reverts a previous commit\n                ]\n          ],\n          'subject-case': [\n                2, // level: error\n                'always', // applicable condition\n                ['sentence-case', 'start-case', 'pascal-case', 'upper-case']\n          ],\n       },\n    };\n    ```\n\n3. Create file `.husky/commit-msg` and add the following code\n\n    ```\n    npx --no-install commitlint --edit $1\n    ```\n\n## Eslint setup\n\n1. Install `eslint` and `@typescript-eslint/parser` as devDependencies\n\n    ```\n    npm install --save-dev eslint @eslint/js @types/eslint__js typescript typescript-eslint\n    ```\n\n2. Create eslint configuration file `.eslintrc.js`\n\n    ```\n    // @ts-check\n    ```\n\nimport eslint from '@eslint/js';\nimport tseslint from 'typescript-eslint';\n\nexport default tseslint.config(\neslint.configs.recommended,\n...tseslint.configs.recommended,\n);\n\n````\n\n3. Run command `npx eslint .`\n\nIt will show the errors in the code\n![Alt text](image-1.png)\n\n4. To fix this, change the following configuration in `.eslint.config.mjs`\n\n   ```\n      // @ts-check\n\n   import eslint from '@eslint/js';\n   import tseslint from 'typescript-eslint';\n\n   export default tseslint.config(\n      {\n         languageOptions: {\n               parserOptions: {\n                  project: true,\n                  tsconfigRootDir: import.meta.dirname,\n               },\n         },\n         files: ['**/*.ts'],\n         extends: [\n               eslint.configs.recommended,\n               ...tseslint.configs.recommended,\n         ],\n         rules: {\n               // this is done so that there is no console while we push code to github production\n               // large number of consoles slow down the performance of the code\n               'no-console': 'off',\n               quotes: ['error', 'single', { allowTemplateLiterals: true }],\n         }\n      }\n   );\n``\n````\n\n## Prettier Setup\n\n1. Install `prettier` and `eslint-config-prettier` as devDependencies\n\n    ```\n    npm install --save-dev prettier eslint-config-prettier\n    ```\n\n    ```\n    npm i --save-dev @types/eslint-config-prettier\n    ```\n\n2. Create a `.prettierrc` file\n\n    ```\n    {\n       \"semi\": false,\n       \"singleQuote\": true,\n       \"tabWidth\": 3,\n       \"useTabs\": true\n    }\n    ```\n\n3. Update eslint.config.mjs file\n\n    ```\n    import eslintConfigPrettier from 'eslint-config-prettier'\n     extends: [\n            eslint.configs.recommended,\n            ...tseslint.configs.recommended,\n            eslintConfigPrettier\n        ],\n    ```\n\n4. Update package.json file\n\n    ```\n    \"scripts\": {\n        \"format:check\": \"prettier . --check\",\n         \"format:fix\": \"prettier . --fix\"\n    },\n     \"lint-staged\": {\n    \"*.ts\": [\n      \"npm run lint:fix\",\n      \"npm run format:fix\"\n    ]\n    },\n    ```\n\n## Environment Setup\n\n1. Install `dotenv-flow` to `.env.production` and `.env.development` during different situations\n\n    ```\n    npm i dotenv-flow\n    ```\n\n2. Install `cross-env` to `NODE_ENV` variable in any OS\n\n    ```\n    npm i cross-env\n    ```\n\n3. Update `package.json`\n\n    ```\n    \"start\": \"cross-env NODE_ENV=production node dist/server.js\",\n     \"dev\": \"cross-env NODE_ENV=development nodemon src/server.ts\",\n    ```\n\n\n## Express setup\n\n1. Install `express` and `@types/express`\n\n    ```\n    npm i express \n    npm i @types/express -D\n    ```\n\n## Logger setup\n\n1. Install `winston` and `@types/winston`\n\n    ```\n    npm i winston\n    ```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemaster17%2Fexpress-ts-backend-production-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemaster17%2Fexpress-ts-backend-production-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemaster17%2Fexpress-ts-backend-production-setup/lists"}