- Firstly show running as the default way.
- Then execute the command
tsc --init
to initialize tsconfig.json file - Previously we've used a trick to compile and run the ts code using script now we're going to do it in a separate way.
- Create 2 folders
server
anddist
. Then moveapp.js
toserver folder
- Please uncomment the
outDir
property and put"./dist""
- Just run
tsc
command in the console and see whether.js
file is created insidedist
folder. - Then run
npm i @types/node -D
to addfs
file sync as dependency and show js code generated for ES version. - Change the
"module": "ES2022"
and see the result - Always we have to run
tsc
and thennode dist/app.js
so let's define a script for this"start": "tsc && node dist/app.js"
- However, we have a simplified way to do this as well
- Then please use
npm install ts-node -D
to install ts-node. - Then replace start script to
"start": "ts-node server/app.ts"
- So, you'll not need the dist directory any more
punsaraprathibha/gdse-62-64-rad-ts-node-project
Sample app to demonstrate the how to create server & dist folders and work with script commands
TypeScript