This document describes how to create shared packages and build/run services in the Cotrav monorepo. This is a centralizes multiple distinct projects, libraries, and apps into a single, unified repository, enabling easier code sharing, dependency management, and consistent tooling/standards across teams.
cotrav-services/ │ ├─ package.json (root – workspaces enabled) │ ├─ packages/ (shared libraries) │ ├─ logger/ │ ├─ errors/ │ ├─ middlewares/ │ └─ tsconfig.json (base TS config for packages) │ ├─ workspace/ (runtime services) │ ├─ auth-service/ │ ├─ booking-service/ │ └─ payment-service/ │ └─ node_modules/
| Tool | Version |
|---|
| Node.js | >= 18.x |
| npm | >= 9.x |
| TypeScript | >= 5.x |
| VS Code | Recommended |
Root package.json
The root enables npm workspaces so shared packages can be consumed without publishing.
cmd
npm install
npm install pino npm install -D @types/node
Error
npm install -D @types/node
npm install express npm install -D @types/express @types/node
package/logger
cmd
npm run build --workspace=packages/logger
package/errors
cmd
npm run build --workspace=packages/errors
Repeat the same steps for:
@cotrav/errors@cotrav/middlewaresOnly business logic differs, structure remains identical.
Example: auth-service
Folder Creation
cd workspace mkdir auth-service cd auth-service npm init -y
Service package.json
{
"name": "auth-service",
"version": "1.0.0",
"private": true,
"type": "commonjs",
"scripts": {
"dev": "ts-node src/app.ts",
"build": "tsc",
"start": "node dist/app.js"
},
"dependencies": {
"express": "^5.0.0",
"dotenv": "^17.0.0",
"@cotrav/logger": "*",
"@cotrav/errors": "*",
"@cotrav/middlewares": "*"
}
}
npm install npm install -D typescript npm install express dotenv jsonwebtoken bcryptjs swagger-ui-express swagger-jsdoc pino
Type deps
npm install -D @types/express @types/node @types/jsonwebtoken @types/bcryptjs @types/swagger-ui-express
Execute below command on root folder “cotrav-services”
npm run build npm run typecheck
npm run dev:auth
npm run clean
npm workspaces list