First, you need to install TypeScript and
ts-node. While TypeScript is the primary compiler,
ts-node provides the ability to execute TypeScript files directly.
1npm install -g typescript ts-node
This command installs TypeScript and
Create a TypeScript file, for example,
hello.ts, with the following content:
1console.log('Hello from TypeScript');
Now, you can run the TypeScript file using
You should see the output: "Hello from TypeScript".
If you prefer not to install packages globally, you can use
npx to run
ts-node without installing it globally:
1npx ts-node hello.ts
Running TypeScript files from the command line is straightforward with