MVC architecture is a software design pattern for developing web applications. It is made up of three parts: Model, View, and Controller.
- Initialize the repo
npm init -y
- Install express
npm install express
-
Create
.gitignorefile and add node_modules -
Create
index.jsfile, and write anyconsole.logto check for output -
Update the scripts in
package.json"scripts": { "start": "node index.js" },
-
Install
huskyandlint-stagedas devDependenciesnpm i husky lint-staged -D -
Initialize
huskynpx husky init
=> A .husky folder would be created
-
Install typescript
Installing it as devDependencies because we don't need it in production
npm i typescript -D -
Setting up
tsconfig.jsonfilenpx tsc --initA tsconfig.json file would be created
-
Update the
tsconfig.jsonfile{ "compilerOptions": { "target": "es6", "module": "commonjs", "outDir": "./dist", "rootDir": "./src", "strict": true, "esModuleInterop": true, "alwaysStrict": true, "strictPropertyInitialization": true, "strictNullChecks": true, "strictFunctionTypes": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "forceConsistentCasingInFileNames": true, } } -
Install
ts-nodeand@types/nodenpm i ts-node @types/node -D
==> Delete the index.js file and create index.ts file inside src folder
-
Install
nodemonas dev dependencynpm i nodemon -D -
Update the scripts in
package.json"scripts": { "start": "node dist/index.js", "dev": "nodemon src/index.ts", "build": "npx tsc" }, -
Update .gitignore file
dist
-
Install
@commitlint/cliand@commitlint/config-conventionalas devDependenciesnpm i @commitlint/cli @commitlint/config-conventional -D -
Create
commitlint.config.jsfile// commitlint.config.js module.exports = { extends: ['@commitlint/cli', '@commitlint/config-conventional'], rules: { 'type-enum': [ 2, // level: error 'always', // applicable condition [ 'feat', // New feature 'fix', // Bug fix 'docs', // Documentation changes 'style', // Code style changes (formatting, missing semi colons, etc.) 'refactor',// Code refactoring (neither fixes a bug nor adds a feature) 'perf', // Performance improvements 'test', // Adding missing tests or correcting existing tests 'build', // Changes affecting the build system or external dependencies 'ci', // Changes to CI configuration files and scripts 'chore', // Other changes that don’t modify src or test files 'revert' // Reverts a previous commit ] ], 'subject-case': [ 2, // level: error 'always', // applicable condition ['sentence-case', 'start-case', 'pascal-case', 'upper-case'] ], }, }; -
Create file
.husky/commit-msgand add the following codenpx --no-install commitlint --edit $1
-
Install
eslintand@typescript-eslint/parseras devDependenciesnpm install --save-dev eslint @eslint/js @types/eslint__js typescript typescript-eslint -
Create eslint configuration file
.eslintrc.js// @ts-check
import eslint from '@eslint/js'; import tseslint from 'typescript-eslint';
export default tseslint.config( eslint.configs.recommended, ...tseslint.configs.recommended, );
3. Run command `npx eslint .`
It will show the errors in the code

4. To fix this, change the following configuration in `.eslint.config.mjs`
```
// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
export default tseslint.config(
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
files: ['**/*.ts'],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
],
rules: {
// this is done so that there is no console while we push code to github production
// large number of consoles slow down the performance of the code
'no-console': 'off',
quotes: ['error', 'single', { allowTemplateLiterals: true }],
}
}
);
``
-
Install
prettierandeslint-config-prettieras devDependenciesnpm install --save-dev prettier eslint-config-prettiernpm i --save-dev @types/eslint-config-prettier -
Create a
.prettierrcfile{ "semi": false, "singleQuote": true, "tabWidth": 3, "useTabs": true } -
Update eslint.config.mjs file
import eslintConfigPrettier from 'eslint-config-prettier' extends: [ eslint.configs.recommended, ...tseslint.configs.recommended, eslintConfigPrettier ], -
Update package.json file
"scripts": { "format:check": "prettier . --check", "format:fix": "prettier . --fix" }, "lint-staged": { "*.ts": [ "npm run lint:fix", "npm run format:fix" ] },
-
Install
dotenv-flowto.env.productionand.env.developmentduring different situationsnpm i dotenv-flow -
Install
cross-envtoNODE_ENVvariable in any OSnpm i cross-env -
Update
package.json"start": "cross-env NODE_ENV=production node dist/server.js", "dev": "cross-env NODE_ENV=development nodemon src/server.ts",
-
Install
expressand@types/expressnpm i express npm i @types/express -D
-
Install
winstonand@types/winstonnpm i winston
