Have you ever runned typescript on Nodejs? Not yet? It's Ok, I'm going to show you how ease is it and without extra skills requirements!

First of all lets make a directory and init an empty npm project:

npm init -y

And now lets install some dependencies:

npm install typescript ts-node @types/node nodemon

As you can see we installed @types/node, that's very important because typescript has to know about node types. Nodemon package is for watching changes and restarting server, you'll how in a second.

Before run this project, it's important to change module in tsconfig.json, change it to "module": "commonjs". Don't forget, this can cause you many headaches :) For more typescript configurations, check this their documentation.

Now lets add a typescript file:

touch server.ts

Add some content inside:

echo "console.log('Typscript works on nodejs')" >> server.ts

And run it:

nodemon --exec ts-node server.ts

Or add this command to package.json scripts, and run it via npm:

...scripts { start: 'nodemon --exec ts-node server.ts' } ...

And run:

npm start

Very impressive, right? Of course this is a very simple implementation, we haven't implemented the deploy, tests and many other things, but this is not our goal for now!

If you have any questions, ask me!