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:
Harikrishnan Gopal
2025-04-15 21:02:58 +05:30
parent 59c12d6668
commit 5d40065667
5 changed files with 359 additions and 1 deletions

27
run.js Normal file
View 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);
});