Why TypeScript?
TypeScript adds static typing to JavaScript, catching errors at compile time and improving code maintainability. Setting up a proper TypeScript environment on your Breeze enables productive server-side development with type safety.
Prerequisites
- A Breeze running Ubuntu 22.04 or later
- Node.js 18+ installed
Step 1: Install TypeScript Globally
sudo npm install -g typescript ts-nodeVerify the installation:
tsc --version
ts-node --versionStep 2: Initialize a Project
mkdir ~/my-ts-project && cd ~/my-ts-project
npm init -y
npm install typescript @types/node --save-dev
npx tsc --initStep 3: Configure tsconfig.json
Edit tsconfig.json for a Node.js project:
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"lib": ["ES2022"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"include": ["src/**/*"]
}Step 4: Add Build Scripts
Update package.json:
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "ts-node src/index.ts",
"watch": "tsc --watch"
}Step 5: Set Up Linting
npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
npx eslint --initUsing with PM2
For production on your Breeze, compile with npm run build and run the JavaScript output with PM2: pm2 start dist/index.js --name my-app.