DEV Community

Cover image for Nodejs setup with Typescript

Posted on

Nodejs setup with Typescript

Setting up Nodejs and Typescript was a little bit of a hurdle for me at the time i was beginning, but turns out it was way easier than i thought. This is going to help you cover a decent set up to get you going.

Firstly i dont think i need to define both technologies, i assume you already know them before reading this post :), if not head over to and to find out about them, so lets get going.

Navigate to your project root folder and run the following terminal commands
npm init -y
After that had initialized a package.json file for you run
npx tsconfig.json
let it run the choose the technology you are using which is node

? Pick the framework you're using: (use arrow keys)
> react
Enter fullscreen mode Exit fullscreen mode

When that runs finish it automatically generates a suitable tsconfig.json file for your node project.
After that you would need to install some dev dependencies
yarn add -D @types/node typescript
npm i @types/node typescript -D
these are basic dependencies node needs to run typescript.
After that add the following scripts to your package.json file.

"scripts": {
   "start": "node dist/index.js",
   "watch": "tsc -w"
Enter fullscreen mode Exit fullscreen mode

The dist folder is produced with your compiled javascript by tsconfig when you run the watch command on your typescript file.
Create a typescript file in your root and run yarn watch or npm watch then also run the start command yarn start or npm start and watch tsconfig compile your typescript file to javascript in the dist folder.

I hope i helped, goodluck :).

Top comments (0)