Static Binaries และ Go Toolchain
Node.js: runtime + node_modules
หัวข้อที่มีชื่อว่า “Node.js: runtime + node_modules”เมื่อคุณจะ ship แอป TypeScript/Node.js คุณต้องเตรียมสิ่งเหล่านี้:
- Node.js runtime (เวอร์ชันที่ถูกต้อง — จัดการด้วย
.nvmrc, Docker base image ฯลฯ) - ทุก npm package ที่โค้ดของคุณพึ่งพา (
node_modules/— มักมีขนาดหลายร้อย MB) - ขั้นตอน transpile (
tsc,esbuild,swcฯลฯ) เพื่อแปลง TypeScript เป็น JavaScript
การ deploy หมายถึงการทำให้แน่ใจว่าทั้งสามชิ้นส่วนนี้มีครบและเวอร์ชันตรงกันบนทุกเครื่องปลายทาง
Go: binary เดียว ไม่ต้องมี runtime
หัวข้อที่มีชื่อว่า “Go: binary เดียว ไม่ต้องมี runtime”โปรแกรม Go คอมไพล์ออกมาเป็น static binary เดี่ยว ที่บรรจุโค้ดของคุณ, dependencies ทั้งหมด และ Go runtime ไว้ในตัว — ลิงก์รวมเข้าไปทั้งหมด เครื่องปลายทางไม่ต้องติดตั้งอะไรเพิ่มเลย ไม่ต้องมี Go ติดตั้ง ไม่ต้องมี package manager ไม่ต้องมี interpreter
# TypeScript deployment checklist# 1. Install Node.js (exact version)node --version # must match .nvmrc
# 2. Install dependenciesnpm install # downloads node_modules/ (~hundreds of MB)
# 3. Buildnpx tsc --build
# 4. Runnode dist/index.js
# Dockerfile must include:# FROM node:20-alpine# COPY package*.json ./# RUN npm ci# COPY dist/ ./dist/# CMD ["node", "dist/index.js"]# Go deployment checklist# 1. Buildgo build -o myapp ./cmd/myapp
# 2. Copy binary to target (that's it)scp myapp user@server:/usr/local/bin/
# 3. Run./myapp
# Dockerfile can be:# FROM scratch <-- empty base image!# COPY myapp /myapp# CMD ["/myapp"]## Final image is often < 10 MB vs 200–500 MB for NodeCross-compilation ด้วยคำสั่งเดียว
หัวข้อที่มีชื่อว่า “Cross-compilation ด้วยคำสั่งเดียว”Go มี cross-compilation มาในตัว แค่ตั้งค่า GOOS (OS ปลายทาง) และ GOARCH (CPU ปลายทาง) เป็น environment variables แล้วรัน go build ไม่ต้องมี toolchain เพิ่ม ไม่ต้อง emulate ด้วย Docker ไม่ต้องมีขั้นตอน CI แยกสำหรับแต่ละ platform
# TypeScript cross-platform is handled by Node.js itself# But native addons (node-gyp, .node files) break cross-platform# pkg / nexe / sea bundle Node + app, but are complex and large# Build for Linux amd64 on a MacGOOS=linux GOARCH=amd64 go build -o myapp-linux ./cmd/myapp
# Build for WindowsGOOS=windows GOARCH=amd64 go build -o myapp.exe ./cmd/myapp
# Build for ARM (Raspberry Pi, AWS Graviton, Apple Silicon)GOOS=linux GOARCH=arm64 go build -o myapp-arm64 ./cmd/myapp
# All three commands run on your laptop — no emulation needed# Each output is a standalone executable for that platformเวลา compile ที่รวดเร็ว
หัวข้อที่มีชื่อว่า “เวลา compile ที่รวดเร็ว”Go ออกแบบมาโดยตั้งความเร็วในการ compile เป็นเป้าหมายระดับ first-class โค้ดเบสขนาดใหญ่ที่อาจใช้เวลาหลายนาทีใน C++ หรือแม้แต่หลายวินาทีใน TypeScript (รัน tsc แบบเต็ม) จะ compile เสร็จในไม่กี่วินาทีหรือต่ำกว่าวินาทีใน Go เพราะ standard library ถูก pre-compile ไว้แล้ว, dependency graph ชัดเจน และไม่มี overhead จากการตรวจจับ circular import
# TypeScript build times (realistic examples)# tsc --build on a medium NestJS project: 5–30s# esbuild (fastest TS bundler): 0.5–3s# But: tsc is also used for type-checking only (no emit)# Type-check of a large monorepo: 30s–3min# Go build times# go build ./... on a medium service: < 2s# go test ./... (build + run tests): 2–10s# go vet ./... (static analysis): < 1s
# The toolchain is one binary — no plugin ecosystem needed:go build # compilego test # testgo vet # static analysisgo fmt # format (gofmt — no config needed)go mod # dependency management