3 const ver = process.version.match(/v(\d+)\.\d+\.\d+/);
5 if (parseInt(ver[1], 10) < 12) {
7 `node.js ${process.version} is not supported. ` +
8 'CyTube requires node v12 or later.'
15 const args = parseArgs();
17 if (args.has('--daemonize')) {
21 require('./lib/main');
23 console.error('FATAL: Failed to require() lib/main.js');
24 handleStartupError(err);
30 console.log('Warning: --daemonize support is experimental. Use with caution.');
32 const spawn = require('child_process').spawn;
33 const path = require('path');
34 const main = path.resolve(__dirname, 'lib', 'main.js');
36 const child = spawn(process.argv[0], [main], {
38 stdio: 'ignore' // TODO: support setting stdout/stderr logfile
42 console.log('Forked with PID ' + child.pid);
44 console.error('FATAL: Failed to fork lib/main.js');
45 handleStartupError(error);
49 function handleStartupError(err) {
50 if (/module version mismatch/i.test(err.message)) {
51 console.error('Module version mismatch, try running `npm rebuild` or ' +
52 'removing the node_modules folder and re-running ' +
55 console.error('Possible causes:\n' +
56 ' * You haven\'t run `npm run build-server` to regenerate ' +
58 ' * You\'ve upgraded node/npm and haven\'t rebuilt dependencies ' +
59 '(try `npm rebuild` or `rm -rf node_modules && npm install`)\n' +
60 ' * A dependency failed to install correctly (check the output ' +
61 'of `npm install` next time)');
64 console.error(err.stack);
68 function parseArgs() {
69 const args = new Map();
70 for (var i = 2; i < process.argv.length; i++) {
71 if (/^--/.test(process.argv[i])) {
73 if (i+1 < process.argv.length) val = process.argv[i+1];
76 args.set(process.argv[i], val);
83 function checkPlayerExists() {
84 const fs = require('fs');
85 const path = require('path');
87 const playerDotJs = path.join(__dirname, 'www', 'js', 'player.js');
89 if (!fs.existsSync(playerDotJs)) {
91 'Missing video player: www/js/player.js. This should have been ' +
92 'automatically generated by the postinstall step of ' +
93 '`npm install`, but you can manually regenerate it by running ' +
94 '`npm run build-player`'