-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstaller.js
50 lines (41 loc) · 1.36 KB
/
installer.js
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
47
48
49
50
//set this as start command on the site called onrender.com you can do node installer.js, this will add like install dependencies and it will start the server
const { exec } = require('child_process');
const dependencies = ['express', 'axios', 'fs'];
const installDependencies = () => {
console.log('Installing dependencies...');
const installCommand = `npm install ${dependencies.join(' ')}`;
const child = exec(installCommand);
child.stdout.on('data', (data) => {
console.log(data.toString());
});
child.stderr.on('data', (data) => {
console.error(data.toString());
});
child.on('exit', (code) => {
if (code === 0) {
console.log('Dependencies installed successfully.');
startServer();
} else {
console.error('Dependency installation failed.');
}
});
};
const startServer = () => {
console.log('Starting Node.js server...');
const startCommand = 'node server.js';
const child = exec(startCommand);
child.stdout.on('data', (data) => {
console.log(data.toString());
});
child.stderr.on('data', (data) => {
console.error(data.toString());
});
child.on('exit', (code) => {
if (code === 0) {
console.log('Node.js server started successfully.');
} else {
console.error('Node.js server failed to start.');
}
});
};
installDependencies();