Step1 - Init ts.config file
npm install -g typescript #required only first time tsc --initStep2 - Update ts.config file
"rootDir": "./src", /* Specify the root folder within your source files. */"outDir": "./dist", /* Specify an output folder for all emitted files. */Step3 - Write TS code
Create src/index.ts
const myName:string = "Dhananjay"console.log(myName)Step4 - Execute
tsc -b #to build the codenode ./dist/index.js #to run the executed fileEvery time when index.ts file is modified, step4 is needed to exec the file
If you want to rebuild the code every time you save the code
Solution
1. Init package and install tsc-watch
npm init -ynpm i tsc-watch -D #installing as dev dependency2. Add dev script
"scripts": { "dev": "tsc-watch --onSuccess \"node ./dist/index.js\""}