Let's perform the following steps to convert our Express.js main application file to use TypeScript so that we can use the same JavaScript syntax between our frontend and backend applications:
- First, we will want to create a new /src directory for all our application files; this makes compilation a bit more straightforward with our source TypeScript files taken from /src, while our compiled JavaScript output will be put into a generated /dist directory:
mkdir src
- Then, we will need to convert our app.js file into a new TypeScript-friendly class definition. We'll start with a new /src/App.ts class file, which will import all our needed libraries using the ES6 module style instead of Node.js's usual CommonJS (require) imports. ...