-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-dev.js
More file actions
46 lines (36 loc) 路 1.07 KB
/
Copy pathstart-dev.js
File metadata and controls
46 lines (36 loc) 路 1.07 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
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import dotenv from 'dotenv';
// Load environment variables
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Function to run a command
const runCommand = (command, args, options = {}) => {
const child = spawn(command, args, {
stdio: 'inherit',
shell: true,
...options
});
child.on('error', (error) => {
console.error(`Error running ${command}:`, error);
});
return child;
};
console.log('馃殌 Starting development server...');
// Start backend server with nodemon
const backend = runCommand('nodemon', ['server.js'], {
env: { ...process.env, NODE_ENV: 'development' }
});
// Start frontend dev server
const frontend = runCommand('npm', ['run', 'client']);
// Handle process termination
const cleanup = () => {
console.log('\n馃洃 Shutting down development servers...');
backend.kill();
frontend.kill();
process.exit(0);
};
process.on('SIGINT', cleanup);
process.on('SIGTERM', cleanup);