データ分析用にスクレイピング処理を作成しております。

```

    const child_process = require('child_process');
    const node = 'node';
    const mainScript = 'hoge_get.js';
    
    process.on('uncaughtException', function(err) {
        console.log(err);
        process.exit(1);
    });
    process.on('unhandledRejection', function(err, p) {
        console.log(err);
        console.log(p);
        process.exit(1);
    });
    
    
    (async() => {
        getScore(`20211208`);
    
        function getScore(id) {
            const exec = child_process.execSync;
            const cmd = `${node} ${mainScript} ${id}`;
            console.log(cmd);
            exec(cmd);
        }
    })();
    
```

上記のようなコードを作成し、mainScriptに対して指定したIDのhtmlファイルをダウンロードする処理の呼び出しを作成ました。

mainScriptのコードでは

```

    (async() => {
        const gameId = process.argv[2]; // id
    
        const browser = await puppeteer.launch();
        const livePage = `https://hoge/result/games/game_${gameId}.html`;
        const page = await browser.newPage();
    
        const dataDir = __dirname + '/data_dmenu';
    
        page.goto(livePage);
    }
    
```

のようなコードでIDに対応したページを開き、処理を行ってまいります。  
上記のように作成し処理の呼び出しを行ったのですが

```

    node hoge_get.js 2021005080 module.js:549 throw err; ^ Error: Cannot find module '/home/ec2-user/hoge/public/hoge_get.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3 { Error: Command failed: node hoge_get.js 2021005080 module.js:549 throw err; ^ Error: Cannot find module '/home/ec2-user/hoge/public/hoge_get.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3 at checkExecSyncError (child_process.js:601:13) at execSync (child_process.js:641:13) at getScore (/home/ec2-user/cutfast/hsb_dmenu_get_yesterday.js:83:9) at /home/ec2-user/cutfast/hsb_dmenu_get_yesterday.js:72:2 at Object.<anonymous> (/home/ec2-user/cutfast/hsb_dmenu_get_yesterday.js:97:3) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) error: null, cmd: 'node hoge_get.js 2021005080', file: '/bin/sh', args: [ '/bin/sh', '-c', 'node hoge_get.js 2021005080' ], options: { shell: true, file: '/bin/sh', args: [ '/bin/sh', '-c', 'node hoge_get.js 2021005080' ], envPairs: [ 'MAIL_PORT=2525', 'DB_HOST=escoredevdb01.cgci6jfuhl5l.ap-northeast-1.rds.amazonaws.com', 'MIX_PUSHER_APP_CLUSTER=mt1', 'DB_PORT=3306', 'SESSION_DRIVER=file', 'MAIL_ENCRYPTION=null', 'PUSHER_APP_SECRET=', 'APP_NAME=eScore Scraper', 'MAIL_USERNAME=null', 'USER=ec2-user', 'BROADCAST_DRIVER=log', 'CACHE_DRIVER=file', 'APP_URL=https://scraper.escore.info', 'REDIS_HOST=127.0.0.1', 'MAIL_PASSWORD=null', 'DB_CONNECTION=mysql', 'DB_DATABASE=scraper', 'REDIS_PASSWORD=null', 'PWD=/home/ec2-user/hoge/public', 'DB_PASSWORD=3nw9C{rKpf', 'PUSHER_APP_ID=', 'APP_DEBUG=true', 'APP_KEY=base64:Bh6kUT4ikikOm4xiGTQONGz+qy9rEWs75F12vOO/FqU=', 'SHLVL=1', 'REDIS_PORT=6379', 'DB_USERNAME=scraper', 'HOME=/home/ec2-user', 'MAIL_DRIVER=smtp', 'LOG_CHANNEL=stack', 'SESSION_LIFETIME=120', 'APP_ENV=local', 'QUEUE_DRIVER=sync', 'MIX_PUSHER_APP_KEY=', 'PUSHER_APP_KEY=', 'PUSHER_APP_CLUSTER=mt1', 'MAIL_HOST=smtp.mailtrap.io', '_=/usr/bin/node' ], killSignal: undefined, stdio: [ [Object], [Object], [Object] ] }, envPairs: [ 'MAIL_PORT=2525', 'DB_HOST=escoredevdb01.cgci6jfuhl5l.ap-northeast-1.rds.amazonaws.com', 'MIX_PUSHER_APP_CLUSTER=mt1', 'DB_PORT=3306', 'SESSION_DRIVER=file', 'MAIL_ENCRYPTION=null', 'PUSHER_APP_SECRET=', 'APP_NAME=eScore Scraper', 'MAIL_USERNAME=null', 'USER=ec2-user', 'BROADCAST_DRIVER=log', 'CACHE_DRIVER=file', 'APP_URL=https://scraper.escore.info', 'REDIS_HOST=127.0.0.1', 'MAIL_PASSWORD=null', 'DB_CONNECTION=mysql', 'DB_DATABASE=scraper', 'REDIS_PASSWORD=null', 'PWD=/home/ec2-user/hoge/public', 'DB_PASSWORD=3nw9C{rKpf', 'PUSHER_APP_ID=', 'APP_DEBUG=true', 'APP_KEY=base64:Bh6kUT4ikikOm4xiGTQONGz+qy9rEWs75F12vOO/FqU=', 'SHLVL=1', 'REDIS_PORT=6379', 'DB_USERNAME=scraper', 'HOME=/home/ec2-user', 'MAIL_DRIVER=smtp', 'LOG_CHANNEL=stack', 'SESSION_LIFETIME=120', 'APP_ENV=local', 'QUEUE_DRIVER=sync', 'MIX_PUSHER_APP_KEY=', 'PUSHER_APP_KEY=', 'PUSHER_APP_CLUSTER=mt1', 'MAIL_HOST=smtp.mailtrap.io', '_=/usr/bin/node' ], stderr: <Buffer 6d 6f 64 75 6c 65 2e 6a 73 3a 35 34 39 0a 20 20 20 20 74 68 72 6f 77 20 65 72 72 3b 0a 20 20 20 20 5e 0a 0a 45 72 72 6f 72 3a 20 43 61 6e 6e 6f 74 20 ... >, stdout: <Buffer >, pid: 15179, output: [ null, <Buffer >, <Buffer 6d 6f 64 75 6c 65 2e 6a 73 3a 35 34 39 0a 20 20 20 20 74 68 72 6f 77 20 65 72 72 3b 0a 20 20 20 20 5e 0a 0a 45 72 72 6f 72 3a 20 43 61 6e 6e 6f 74 20 ... > ], signal: null, status: 1 } Promise { <rejected> { Error: Command failed: node hoge_get.js 2021005080 module.js:549 throw err; ^ Error: Cannot find module '/home/ec2-user/hoge/public/hoge_get.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Function.Module.runMain (module.js:693:10) at startup (bootstrap_node.js:191:16) at bootstrap_node.js:612:3 at checkExecSyncError (child_process.js:601:13) at execSync (child_process.js:641:13) at getScore (/home/ec2-user/cutfast/hsb_dmenu_get_yesterday.js:83:9) at /home/ec2-user/cutfast/hsb_dmenu_get_yesterday.js:72:2 at Object.<anonymous> (/home/ec2-user/cutfast/hsb_dmenu_get_yesterday.js:97:3) at Module._compile (module.js:652:30) at Object.Module._extensions..js (module.js:663:10) at Module.load (module.js:565:32) at tryModuleLoad (module.js:505:12) at Function.Module._load (module.js:497:3) error: null, cmd: 'node hoge_get.js 2021005080', file: '/bin/sh', args: [ '/bin/sh', '-c', 'node hoge_get.js 2021005080' ], options: { shell: true, file: '/bin/sh', args: [Array], envPairs: [Array], killSignal: undefined, stdio: [Array] }, envPairs: [ 'MAIL_PORT=2525', 'DB_HOST=escoredevdb01.cgci6jfuhl5l.ap-northeast-1.rds.amazonaws.com', 'MIX_PUSHER_APP_CLUSTER=mt1', 'DB_PORT=3306', 'SESSION_DRIVER=file', 'MAIL_ENCRYPTION=null', 'PUSHER_APP_SECRET=', 'APP_NAME=eScore Scraper', 'MAIL_USERNAME=null', 'USER=ec2-user', 'BROADCAST_DRIVER=log', 'CACHE_DRIVER=file', 'APP_URL=https://scraper.escore.info', 'REDIS_HOST=127.0.0.1', 'MAIL_PASSWORD=null', 'DB_CONNECTION=mysql', 'DB_DATABASE=scraper', 'REDIS_PASSWORD=null', 'PWD=/home/ec2-user/hoge/public', 'DB_PASSWORD=3nw9C{rKpf', 'PUSHER_APP_ID=', 'APP_DEBUG=true', 'APP_KEY=base64:Bh6kUT4ikikOm4xiGTQONGz+qy9rEWs75F12vOO/FqU=', 'SHLVL=1', 'REDIS_PORT=6379', 'DB_USERNAME=scraper', 'HOME=/home/ec2-user', 'MAIL_DRIVER=smtp', 'LOG_CHANNEL=stack', 'SESSION_LIFETIME=120', 'APP_ENV=local', 'QUEUE_DRIVER=sync', 'MIX_PUSHER_APP_KEY=', 'PUSHER_APP_KEY=', 'PUSHER_APP_CLUSTER=mt1', 'MAIL_HOST=smtp.mailtrap.io', '_=/usr/bin/node' ], stderr: <Buffer 6d 6f 64 75 6c 65 2e 6a 73 3a 35 34 39 0a 20 20 20 20 74 68 72 6f 77 20 65 72 72 3b 0a 20 20 20 20 5e 0a 0a 45 72 72 6f 72 3a 20 43 61 6e 6e 6f 74 20 ... >, stdout: <Buffer >, pid: 15179, output: [ null, <Buffer >, <Buffer 6d 6f 64 75 6c 65 2e 6a 73 3a 35 34 39 0a 20 20 20 20 74 68 72 6f 77 20 65 72 72 3b 0a 20 20 20 20 5e 0a 0a 45 72 72 6f 72 3a 20 43 61 6e 6e 6f 74 20 ... > ], signal: null, status: 1 } }
    
```

というエラーが発生しております。  
hoge_get.jsファイルは「/home/ec2-user/hoge」直下においているのですが、  
エラーでは「/home/ec2-user/hoge/public/」に参照を行おうとしており、原因がよくわかっておりません。

こちら呼び出し設定のどこに問題があるのでしょうか。
CC BY-SA 4.0
2021-12-08T01:37:41.430
84014
2021-12-08T01:37:41.430
29606
question
javascript amazon-ec2
javascriptでのID付き処理呼び出しでエラーが発生する