start-production.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env node
  2. import { spawn } from 'child_process';
  3. import path from 'path';
  4. import { fileURLToPath } from 'url';
  5. const __filename = fileURLToPath(import.meta.url);
  6. const __dirname = path.dirname(__filename);
  7. // Set production environment
  8. process.env.NODE_ENV = 'production';
  9. // Load production environment file if it exists
  10. const envFile = path.join(__dirname, '.env.production');
  11. console.log('🚀 Starting Gooneral Wheelchair Backend in Production Mode');
  12. console.log('📁 Environment:', process.env.NODE_ENV);
  13. console.log('🌐 Port:', process.env.PORT || 3001);
  14. // Start the server
  15. const server = spawn('node', ['server.js'], {
  16. cwd: __dirname,
  17. stdio: 'inherit',
  18. env: {
  19. ...process.env,
  20. NODE_ENV: 'production'
  21. }
  22. });
  23. server.on('error', (err) => {
  24. console.error('❌ Failed to start server:', err);
  25. process.exit(1);
  26. });
  27. server.on('close', (code) => {
  28. console.log(`🛑 Server process exited with code ${code}`);
  29. process.exit(code);
  30. });
  31. // Graceful shutdown
  32. process.on('SIGINT', () => {
  33. console.log('\n🛑 Received SIGINT, shutting down gracefully...');
  34. server.kill('SIGINT');
  35. });
  36. process.on('SIGTERM', () => {
  37. console.log('\n🛑 Received SIGTERM, shutting down gracefully...');
  38. server.kill('SIGTERM');
  39. });