npm init -y # Setup a new project with NPM using the defaults
npm install --save-dev typescript # install typescript as a dev dependency
npx -c "tsc --init" # Create a basic configuration for our compiler// index.ts
const x: number = 5;
console.log('#######', x);Compile & Run:
npx -c "tsc -p ." && node .- Set
outDirto"./dist", androotDirto"./src"intsconfig.json - Remove the generated
index.js - Move
index.tsintosrcdirectory
- Add a new script inside your
package.json, called:"watch-ts": "tsc -p . -w" - Run
npm run watch-ts - Run
node dist - Change your
index.tsto print something else - Re-run
node dist - Profit!
- Run
npm install --save-dev nodemon concurrently - Add new scripts:
{ ... "run-js": "nodemon dist/index.js", "start": "concurrently 'npm:watch-ts' 'npm:run-js'" } - Run
npm start, and change files for fun and profit :)