Skip to content

Instantly share code, notes, and snippets.

@VineetKumarKushwaha
Last active July 5, 2020 13:09
Show Gist options
  • Save VineetKumarKushwaha/4d13e92b04a4d12c11432fc552b7ec6b to your computer and use it in GitHub Desktop.
Save VineetKumarKushwaha/4d13e92b04a4d12c11432fc552b7ec6b to your computer and use it in GitHub Desktop.
Typescript configuration for node Js with eslint and prettierrc
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"settings": {
"import/resolver": {
"typescript": {} // this loads <rootdir>/tsconfig.json to eslint
}
},
"plugins": ["@typescript-eslint", "import"],
"extends": ["airbnb-base", "plugin:@typescript-eslint/recommended"],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"indent": ["error", 4],
"comma-dangle": ["error", "never"],
"arrow-parens": "off",
"consistent-return": "off",
"quotes": ["error", "double"],
"lines-between-class-members": "off",
"import/extensions": "off",
"implicit-arrow-linebreak": "off",
"import/prefer-default-export": "off",
"@typescript-eslint/no-explicit-any": [
"warn",
{
"fixToUnknown": true,
"ignoreRestArgs": true
}
]
}
}
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": true,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"singleQuote": false,
"tabWidth": 4,
"useTabs": false,
"parser": "typescript",
"semi": true,
"trailingComma": "none"
}
// this file should be under types folder.
// place to write global types
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "build/index.js",
"scripts": {
"start": "ts-node-dev src/index.ts",
"build": "rm -rf ./build/ && npm run eslint && tsc",
"tsc": "tsc",
"eslint": "eslint src/**/*.ts",
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
},
"dependencies": {},
"devDependencies": {
"@types/node": "^14.0.5",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"eslint": "^7.1.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-plugin-import": "^2.20.2",
"prettier": "^2.0.5",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "3.6.4"
},
"engines": {
"node": ">=10"
},
"author": "",
"license": "ISC"
}
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"sourceMap": true,
"outDir": "./build/",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"moduleResolution": "node",
"baseUrl": "./src/",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*.ts", "types/"],
"exclude": ["node_modules"],
"files": ["types/globals.d.ts"]
}
@VineetKumarKushwaha
Copy link
Author

VineetKumarKushwaha commented Jul 5, 2020

Options to start the server in production and development mode.

tsc :- Transpile typescript to javascript and able to watch and reg-generate the bundle.
ts-node:- Run-time environment that supports typescript under the hood. Has watch mode
ts-node-dev:- extend ts-node with the ability to cache previous compilation to make transpiling faster for every change.
nodemon:- nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected
node:- convert first from typescript to javascript and then start the node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment