Add code to run npm start in both client & server
- Created a `run.js` script to automate the execution of `npm start` in both `client` and `server` directories. - Added a check for `node_modules` to run `npm install` if missing before starting the applications. - Updated root `package.json` with `install-all` and `start-all` scripts for easy installation and starting of both client and server simultaneously.
This commit is contained in:
27
run.js
Normal file
27
run.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { spawn } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const directories = ['client', 'server'];
|
||||
|
||||
function runCommand(command, args, cwd) {
|
||||
const proc = spawn(command, args, { cwd, stdio: 'inherit', shell: true });
|
||||
proc.on('close', (code) => {
|
||||
if (code !== 0) {
|
||||
console.error(`Process in ${cwd} exited with code ${code}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
directories.forEach(dir => {
|
||||
const fullPath = path.join(__dirname, dir);
|
||||
|
||||
// Check if node_modules exists; if not, run npm install first
|
||||
if (!fs.existsSync(path.join(fullPath, 'node_modules'))) {
|
||||
console.log(`node_modules not found in ${dir}. Running npm install...`);
|
||||
runCommand('npm', ['install'], fullPath);
|
||||
}
|
||||
|
||||
console.log(`Starting npm start in ${dir}`);
|
||||
runCommand('npm', ['start'], fullPath);
|
||||
});
|
||||
Reference in New Issue
Block a user