node.sh 1023 B

1234567891011121314151617181920212223
  1. #!/usr/bin/env bash
  2. # ZCode Sites start.sh for a Node.js server. Runs in the foreground on 0.0.0.0:3000.
  3. # Dependencies must already be in ./node_modules (installed for linux x64); never install here.
  4. set -euo pipefail
  5. cd "$(dirname "${BASH_SOURCE[0]}")"
  6. export NODE_ENV=production
  7. export PORT="${PORT:-3000}"
  8. # Different frameworks read different variables for the bind address; set all of them.
  9. export HOST=0.0.0.0 HOSTNAME=0.0.0.0
  10. # The instance has 1 GB; leave headroom for non-heap memory.
  11. export NODE_OPTIONS="${NODE_OPTIONS:---max-old-space-size=768}"
  12. # Writable but temporary storage (lost when the instance is recycled).
  13. export DATA_DIR="${DATA_DIR:-$PWD/data}"
  14. mkdir -p "$DATA_DIR"
  15. # ADJUST: the server entry. Examples:
  16. # Next.js standalone: exec node server.js
  17. # Nuxt (Nitro): exec node .output/server/index.mjs
  18. # SvelteKit adapter-node: exec node build
  19. # Astro @astrojs/node: exec node dist/server/entry.mjs
  20. # Express/Fastify/Nest/Hono (compiled): exec node dist/main.js
  21. exec node server.js