3. Typescript Journey - Hello World
Run your app with Node
- Create src folder
mkdir src cd src
- Create typescript file
touch index.ts
- Initialize tsc
tsc --init
- Output “Hello World” to console. Paste code into index.ts
console.log("Hello World")
- Create .js file from typescript
tsc
- Run your app
node index.js
- Remove .js file
rm index.js
Run your app with ts-node
Another alternative to run your app is to use ts-node, this does not require creating a js file
- Install ts-node
npm install -g ts-node typescript '@types/node'
- Add ts-node to docker image so you don’t have to install everytime. In your dockerfile add the following line
RUN npm install -g ts-node typescript '@types/node'
- Run your ts file
ts-node index.ts