Everything else remains the same (Create a new project, add typescript, add express…)
The only thing that’s different is that tsc
doesn’t perform great with turborepo
You can use either tsup
or esbuild
for building your backend application
-
Create
apps/backend
-
Initialize empty ts repo
npm init -y
npx tsc --init
- Use base tsconfig (Ref - https://github.com/vercel/turbo/blob/main/examples/kitchen-sink/apps/api/tsconfig.json )
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"lib": ["ES2015"],
"module": "CommonJS",
"outDir": "./dist",
},
"exclude": ["node_modules"],
"include": ["."]
}
- Add dependencies
npm i express @types/express
- Add
src/index.ts
import express from "express";
const app = express()
app.get("/", (req, res) => {
res.json({
message: "hello world"
});
})
- Update turbo.json
{
"extends": ["//"],
"pipeline": {
"build": {
"outputs": ["dist/**"]
}
}
}
- Install esbuild
npm install esbuild
- Add build script to package.json
"build": "esbuild src/index.ts --platform=node --bundle --outdir=dist"