Automate TypeScript Development with Nodemon and Concurrently

Once you have setup TypeScript, follow these steps:

  1. In your command line, run the following command to creates a tsconfig.json file:
tsc --init

2. In the compilerOptions section, update the rootDir and outDir paths. Set sourceRoot to where your TypeScript files will be stored, and outDir to where you want the transpiled JavaScript files to be generated.

{
    "compilerOptions": {
        /* Folder for TypeScript files */
        "rootDir": "./src/", 

        /* Folder for built JavaScript files */
        "outDir": "./build/",
    }
}

3. Install the following packages:

4. In your command line, run the following command to create a package.json file

npm init

5. Add the following scripts to the package.json file

"scripts": {
    "build": "tsc --watch",
    "execute": "nodemon build/index.js",
    "start": "concurrently \\"npm run build\\" \\"npm run execute\\" "
  }

With this setup, when you create and save any TypeScript file(s) in ./src/, the TypeScript compiler will automatically generate the corresponding JavaScript file(s) in ./build/.

Concurrently, nodemon will automatically execute the JavaScript file whenever it changes.