Pregunta

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?

¿Fue útil?

Solución

tsc is a compiler not a repl.

You need to write your typescript , compile it with tsc then execute it with nodejs.

Otros consejos

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

Maybe this answer is not necessary but is very simple what you ask.

after write

console.log('test'); Save this by example as test.ts

then run the command tsc test.ts (this will compile your code to JS) you will see a new file created by tsc with the name test.js

Now you can run your test by typing: node test.js

I hope it works for you

You need to install this dev depending

npm i -D @types/node
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top