Step by step using Typescript (TS) in Express (Node.js) Project
In this tutorial, you will learn how to use Typescript(TS) in Express (Node.js) project.
- Basic knowledge in Typescript (TS), Node.js and Express
- Having a Node version from v12 upwards, including Node 12.
1. Set up the project
The first step is to create a directory for the project and initialise it. Run the following commands to create an empty directory called
express-nodejs-ts, and change the current directory to it:
Now that you are in the
express-nodejs-ts directory, you have to initialise the Node project. To do so, run the following command:
npm init -y
-y flag in the above command generates the
package.json file with the default values. Instead of adding information like the name and description of the project ourselves, npm initialises the file with default values.
The project is initialised, and thus you can move to the next section — adding the project dependencies.
2. Add dependencies
The next step is to add the project dependencies (Express and Typescript) by running the following commands:
npm install express
npm install typescript ts-node @types/node @types/express --save-dev
Why save everything Typescript-related as
Moving forward, your
package.json should look as follows after installing all the dependencies:
"description": "Express project with TypeScript",
"test": "echo \"Error: no test…