Let's load TypeScript globally first
npm i -g typescript@next // latest version published daily
You can try to make sure typescript is loaded
tsc --version
Let's create source folder and work file
src/app.ts
For the TypeScript configuration file
tsc --init // tsconfig.json file
TypeScript configuration file can be used briefly as in the repo or according to your request
- You can output javascript to TypeScript file with tsc command.
tsc // app.ts ---> app.js
Let's create the package.json file
npm init -y
We install npm i express with express
npm i express
For other addictions
npm i -D typescript ts-node nodemon @types/node @types/express
Edit package.json file scripts
"scripts": {
"start": "node dist/app.js",
"dev": "nodemon src/app.ts",
"build": "tsc -p ."
}
The app.ts file is prepared
import express, {Application, Request, Response, NextFunction} from 'express';
const app:Application = express();
app.get('/', (req: Request, res: Response, next: NextFunction) => {
res.send('Hello world');
});
app.listen(5000, () => console.log('Server running'));
Use the command below to test
npm run dev
To get build and run
npm run build