I am trying out TypeScript on Node.js.
I have installed it using
npm install typescript
When just run tsc
:
:~$ tsc
Version 1.0.1.0
Syntax: tsc [options] [file ..]
So, I am trying to run simple code:
console.log('test');
which is not outputing nothing.
How can I output anyting in console from typescript running on node.js?
tsc is a compiler not a repl.
You need to write your typescript , compile it with tsc then execute it with nodejs.
With ts-node, which is a TypeScript execution environment, you can now execute TypeScript with node as you expected from the tsc compiler.
After installing ts-node you can run your example directly as
ts-node -e 'console.log('test')'
or you can run a TypeScript file as:
ts-node script.ts
Please find further details on the ts-node npm page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With