· Technology · 1 min read

Starting a Typescript Node project

There’s no good reason to not use Typescript anymore. This is a quick guide on how to start a NodeJS project with Typescript from the get-go.

Starting a fresh NodeJS project is as simple as running yarn init and following the prompts (unless you like crafting package.json files yourself)

With your vanilla project initialised you can start writing Javascript referencing external packages. But why settle for second best when enabling Typescript couldn’t be easier.

Install the requisite packages -

sh
yarn add typescript ts-node
yarn add -D @types/node

Initialise the tsconfig.json file -

sh
yarn run tsc --init

Now you can run Typescript files with -

sh
yarn run ts-node index.ts

To simplify things, you can add a script to your package.json -

json
"scripts": {
  "start": "node -r ts-node/register index.ts"
}

Then you can just start your project with yarn start

That’s all it takes. Completely self contained, no additional dependencies or configuration required.