blog post hero image

Typescript Setup (NodeJS)

| Oliver Rademaker

NODEJS TYPESCRIPT CODE

  1. Install Nodejs (npm)
  2. Init Project
    npm init
    
  3. Install Typescript and TSlint into the project
    npm install --save-dev --save-exact typescript tslint
    
  4. Init tsconfig.json and configure
    npx tsc --init
    
    {
    	"compilerOptions": {    		
            "target": "ES6",
            "lib": ["ES6"],
            "experimentalDecorators": true,
            "emitDecoratorMetadata": true,
            "module": "commonjs",
            "rootDir": "src",
            "baseUrl": "./",
                "paths": {
                    "*": [
                        "node_modules/*",
                        "src/_types/*"
                    ]
                },
            },
            "resolveJsonModule": true,
            "sourceMap": true,
            "outDir": "dist",
            "esModuleInterop": true,
            "forceConsistentCasingInFileNames": true,
            "strict": true,
            "skipLibCheck": true,
            "include": [
                "src/**/*.ts"
            ],
            "exclude": [
                "node_modules",
                "**/*.spec.ts"
            ]
        }
    
  5. Init tslint.json and configure
    npx tslint --init
    
    {
    	"defaultSeverity": "error",
    	"extends": ["tslint:recommended"],
    	"jsRules": {},
    	"rules": {
    		"no-console": false
    	},
    	"rulesDirectory": [],
        "include": ["src/**/*"],
        "exclude": ["node_modules", "**/*.spec.ts"]
    }
    
  6. Update package.json
    {
        "scripts": {
            "start": "tsc && node dist/app.js"
         },
    }