


Either locally in the project or globally in our machine.

There are two ways of using TypeScript in a NodeJS app. Because by default, this app will use JavaScript. We can now install the dependencies to enable TypeScript in the project. Include: tells the compiler to include files that are in the src directory and sub-directory.Įxclude: will exclude the files or folders passed in the array during compile-time. RootDir: informs TypeScript to compile every. OutDir: tells the compiler to put the compiled code into the dist/js folder. Here we have four main properties to underline: Now, we need to configure the tsconfig.json file to help the compiler along following our preferences. The controllers, types, and routes are also in their respective folder names. We also have an app.ts file that is the entry point of the server. The dist directory will serve as an output folder once the code has compiled to plain JavaScript. Next, structure the project as follows: ├── distĪs you can see, this file structure is relatively simple. You can skip it by adding a -y flag to the command. It will ask for a couple of questions and then initialize the app. To create a new NodeJS App, you need to run this command on the terminal: yarn init If you're new to this, you can start with A Practical Guide to TypeScript or How to build an API from scratch with Node JS, Express, and MongoDB to get most out of this tutorial. API with NodeJS, Express, MongoDB and TypeScript Getting set up API with NodeJS, Express, MongoDB and TypeScript.In this tutorial, we will be using TypeScript on both sides (server and client) to build a Todo App from scratch with React, NodeJS, Express, and MongoDB.
