-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·77 lines (56 loc) · 1.51 KB
/
setup.sh
File metadata and controls
executable file
·77 lines (56 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# -------------------------------
# Microservice Setup Script
# Node.js + TypeScript + Express + KafkaJS
# -------------------------------
set -e
SERVICE_NAME=$(basename "$PWD")
echo "📦 Initializing $SERVICE_NAME..."
npm init -y
npm install express kafkajs dotenv pg
npm install --save-dev @types/kafkajs
npm install --save-dev typescript ts-node-dev @types/node @types/express @types/dotenv @types/pg
touch .env .dockerignore
cat > .dockerignore <<'EOF'
node_modules/
build/
.env
EOF
mkdir -p src build
mkdir -p src/kafka src/controller src/route
cat > tsconfig.json <<'EOF'
{
"compilerOptions": {
"target": "es2020",
"module": "NodeNext",
"lib": ["es2020"],
"allowJs": true,
"outDir": "build",
"rootDir": "src",
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
EOF
npx npm pkg set scripts.dev="ts-node-dev --respawn src/index.ts"
npx npm pkg set scripts.build="tsc"
npx npm pkg set scripts.start="node build/index.js"
cat > src/index.ts <<'EOF'
import express from 'express';
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json());
app.get('/', (_req, res) => {
res.send('Welcome to the service!');
});
app.listen(PORT, () => {
console.log(`🚀 Server is running on port ${PORT}`);
});
EOF
echo "✅ $SERVICE_NAME setup complete."
echo "👉 Run 'npm run dev' to start developing."