'AWS Elastic Beanstalk - Node.js app not working

I tried to setup my node.js app with AWS Elastic Beanstalk and I keep getting errors in my environment. The code is in a private GitHub Repo and I connected it via CodePipeline in AWS. Both (Source & Deploy) are successful but my app environment keeps throwing errors.

I am new to both, node.js and AWS, and tried to follow along some Youtube tutorials but for me it keeps throwing errors. In my localhost everything is working fine.

Those are the AWS logs:

----------------------------------------
/var/log/eb-engine.log
----------------------------------------
2022/02/28 01:17:43.909573 [INFO] Running command /bin/sh -c systemctl disable nginx.service
2022/02/28 01:17:44.017151 [INFO] Running command /bin/sh -c systemctl daemon-reload
2022/02/28 01:17:44.118473 [INFO] Running command /bin/sh -c systemctl reset-failed
2022/02/28 01:17:44.122856 [INFO] Executing instruction: FlipApplication
2022/02/28 01:17:44.122871 [INFO] Fetching environment variables...
2022/02/28 01:17:44.122879 [INFO] setting default port 8080 to application
2022/02/28 01:17:44.123027 [INFO] Purge old process...
2022/02/28 01:17:44.123046 [INFO] Running command /bin/sh -c systemctl stop eb-app.target
2022/02/28 01:17:44.132714 [INFO] Running command /bin/sh -c systemctl show -p ConsistsOf eb-app.target | cut -d= -f2
2022/02/28 01:17:44.146197 [INFO] web.service

2022/02/28 01:17:44.146219 [INFO] Running command /bin/sh -c systemctl show -p PartOf web.service
2022/02/28 01:17:44.152823 [INFO] Running command /bin/sh -c systemctl is-active web.service
2022/02/28 01:17:44.156369 [INFO] Running command /bin/sh -c systemctl disable web.service
2022/02/28 01:17:44.258710 [INFO] Running command /bin/sh -c systemctl daemon-reload
2022/02/28 01:17:44.357617 [INFO] Running command /bin/sh -c systemctl reset-failed
2022/02/28 01:17:44.362032 [INFO] Register application processes...
2022/02/28 01:17:44.362042 [INFO] Registering the proc: web

2022/02/28 01:17:44.362053 [INFO] Running command /bin/sh -c systemctl show -p PartOf web.service
2022/02/28 01:17:44.368445 [INFO] Running command /bin/sh -c systemctl daemon-reload
2022/02/28 01:17:44.454689 [INFO] Running command /bin/sh -c systemctl reset-failed
2022/02/28 01:17:44.459250 [INFO] Running command /bin/sh -c systemctl is-enabled eb-app.target
2022/02/28 01:17:44.462954 [INFO] Running command /bin/sh -c systemctl enable eb-app.target
2022/02/28 01:17:44.549565 [INFO] Running command /bin/sh -c systemctl start eb-app.target
2022/02/28 01:17:44.554884 [INFO] Running command /bin/sh -c systemctl enable web.service
2022/02/28 01:17:44.653485 [INFO] Running command /bin/sh -c systemctl show -p PartOf web.service
2022/02/28 01:17:44.658836 [INFO] Running command /bin/sh -c systemctl is-active web.service
2022/02/28 01:17:44.662430 [INFO] Running command /bin/sh -c systemctl start web.service
2022/02/28 01:17:44.679504 [INFO] Executing instruction: start X-Ray
2022/02/28 01:17:44.679516 [INFO] X-Ray is not enabled.
2022/02/28 01:17:44.679521 [INFO] Executing instruction: start proxy with new configuration
2022/02/28 01:17:44.679537 [INFO] Running command /bin/sh -c /usr/sbin/nginx -t -c /var/proxy/staging/nginx/nginx.conf
2022/02/28 01:17:44.697673 [INFO] Running command /bin/sh -c cp -rp /var/proxy/staging/nginx/* /etc/nginx
2022/02/28 01:17:44.705568 [INFO] Running command /bin/sh -c systemctl show -p PartOf nginx.service
2022/02/28 01:17:44.717561 [INFO] Running command /bin/sh -c systemctl daemon-reload
2022/02/28 01:17:44.844814 [INFO] Running command /bin/sh -c systemctl reset-failed
2022/02/28 01:17:44.854075 [INFO] Running command /bin/sh -c systemctl show -p PartOf nginx.service
2022/02/28 01:17:44.863999 [INFO] Running command /bin/sh -c systemctl is-active nginx.service
2022/02/28 01:17:44.874023 [INFO] Running command /bin/sh -c systemctl start nginx.service
2022/02/28 01:17:44.951543 [INFO] Executing instruction: configureSqsd
2022/02/28 01:17:44.951557 [INFO] This is a web server environment instance, skip configure sqsd daemon ...
2022/02/28 01:17:44.951562 [INFO] Executing instruction: startSqsd
2022/02/28 01:17:44.951565 [INFO] This is a web server environment instance, skip start sqsd daemon ...
2022/02/28 01:17:44.951569 [INFO] Executing instruction: Track pids in healthd
2022/02/28 01:17:44.951573 [INFO] This is an enhanced health env...
2022/02/28 01:17:44.951585 [INFO] Running command /bin/sh -c systemctl show -p ConsistsOf aws-eb.target | cut -d= -f2
2022/02/28 01:17:44.965083 [INFO] healthd.service cfn-hup.service nginx.service

2022/02/28 01:17:44.965102 [INFO] Running command /bin/sh -c systemctl show -p ConsistsOf eb-app.target | cut -d= -f2
2022/02/28 01:17:44.978576 [INFO] web.service

2022/02/28 01:17:44.978720 [INFO] Executing instruction: RunAppDeployPostDeployHooks
2022/02/28 01:17:44.978733 [INFO] Executing platform hooks in .platform/hooks/postdeploy/
2022/02/28 01:17:44.978748 [INFO] The dir .platform/hooks/postdeploy/ does not exist
2022/02/28 01:17:44.978754 [INFO] Executing cleanup logic
2022/02/28 01:17:44.978841 [INFO] CommandService Response: {"status":"SUCCESS","api_version":"1.0","results":[{"status":"SUCCESS","msg":"Engine execution has succeeded.","returncode":0,"events":[{"msg":"Instance deployment: You didn't specify a Node.js version in the 'package.json' file in your source bundle. The deployment didn't install a specific Node.js version.","timestamp":1646011056,"severity":"INFO"},{"msg":"Instance deployment completed successfully.","timestamp":1646011064,"severity":"INFO"}]}]}

2022/02/28 01:17:44.979722 [INFO] Platform Engine finished execution on command: app-deploy

2022/02/28 01:19:06.377594 [INFO] Starting...
2022/02/28 01:19:06.377634 [INFO] Starting EBPlatform-PlatformEngine
2022/02/28 01:19:06.377649 [INFO] reading event message file
2022/02/28 01:19:06.377741 [INFO] no eb envtier info file found, skip loading env tier info.
2022/02/28 01:19:06.377804 [INFO] Engine received EB command cfn-hup-exec

2022/02/28 01:19:06.466161 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:eu-central-1:933252075322:stack/awseb-e-pwf3uiggxx-stack/88a96680-9833-11ec-be39-0270e4377b56 -r AWSEBAutoScalingGroup --region eu-central-1
2022/02/28 01:19:06.768115 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:eu-central-1:933252075322:stack/awseb-e-pwf3uiggxx-stack/88a96680-9833-11ec-be39-0270e4377b56 -r AWSEBBeanstalkMetadata --region eu-central-1
2022/02/28 01:19:07.071759 [INFO] checking whether command tail-log is applicable to this instance...
2022/02/28 01:19:07.071772 [INFO] this command is applicable to the instance, thus instance should execute command
2022/02/28 01:19:07.071777 [INFO] Engine command: (tail-log)

2022/02/28 01:19:07.071825 [INFO] Executing instruction: GetTailLogs
2022/02/28 01:19:07.071830 [INFO] Tail Logs...
2022/02/28 01:19:07.072117 [INFO] Running command /bin/sh -c tail -n 100 /tmp/sample-app.log
2022/02/28 01:19:07.073856 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-engine.log
2022/02/28 01:19:07.075382 [INFO] Running command /bin/sh -c tail -n 100 /var/log/web.stdout.log
2022/02/28 01:19:07.076897 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-hooks.log
2022/02/28 01:19:07.078347 [INFO] Running command /bin/sh -c tail -n 100 /var/log/nginx/access.log
2022/02/28 01:19:07.079851 [INFO] Running command /bin/sh -c tail -n 100 /var/log/nginx/error.log
2022/02/28 01:19:07.195366 [INFO] Executing cleanup logic
2022/02/28 01:19:07.195464 [INFO] CommandService Response: {"status":"SUCCESS","api_version":"1.0","results":[{"status":"SUCCESS","msg":"Engine execution has succeeded.","returncode":0,"events":[{"msg":"Instance deployment completed successfully.","timestamp":1646011147,"severity":"INFO"}]}]}

2022/02/28 01:19:07.195479 [INFO] Platform Engine finished execution on command: tail-log

2022/02/28 16:20:27.384363 [INFO] Starting...
2022/02/28 16:20:27.384403 [INFO] Starting EBPlatform-PlatformEngine
2022/02/28 16:20:27.384418 [INFO] reading event message file
2022/02/28 16:20:27.384506 [INFO] no eb envtier info file found, skip loading env tier info.
2022/02/28 16:20:27.384572 [INFO] Engine received EB command cfn-hup-exec

2022/02/28 16:20:27.470718 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:eu-central-1:933252075322:stack/awseb-e-pwf3uiggxx-stack/88a96680-9833-11ec-be39-0270e4377b56 -r AWSEBAutoScalingGroup --region eu-central-1
2022/02/28 16:20:27.765404 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:eu-central-1:933252075322:stack/awseb-e-pwf3uiggxx-stack/88a96680-9833-11ec-be39-0270e4377b56 -r AWSEBBeanstalkMetadata --region eu-central-1
2022/02/28 16:20:28.068120 [INFO] checking whether command tail-log is applicable to this instance...
2022/02/28 16:20:28.068134 [INFO] this command is applicable to the instance, thus instance should execute command
2022/02/28 16:20:28.068139 [INFO] Engine command: (tail-log)

2022/02/28 16:20:28.068209 [INFO] Executing instruction: GetTailLogs
2022/02/28 16:20:28.068215 [INFO] Tail Logs...
2022/02/28 16:20:28.068599 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-engine.log


----------------------------------------
/var/log/web.stdout.log
----------------------------------------
Feb 28 01:15:29 ip-172-31-47-138 web: > [email protected] start /var/app/current
Feb 28 01:15:29 ip-172-31-47-138 web: > node app.js
Feb 28 01:15:30 ip-172-31-47-138 web: Server running at http://127.0.0.1:8080/
Feb 28 01:17:45 ip-172-31-47-138 web: > [email protected] start /var/app/current
Feb 28 01:17:45 ip-172-31-47-138 web: > nodemon app.js
Feb 28 01:17:45 ip-172-31-47-138 web: sh: nodemon: command not found
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! code ELIFECYCLE
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! syscall spawn
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! file sh
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! errno ENOENT
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! [email protected] start: `nodemon app.js`
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! spawn ENOENT
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR!
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! Failed at the [email protected] start script.
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! A complete log of this run can be found in:
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR!     /home/webapp/.npm/_logs/2022-02-28T01_17_45_144Z-debug.log
Feb 28 01:17:45 ip-172-31-47-138 web: > [email protected] start /var/app/current
Feb 28 01:17:45 ip-172-31-47-138 web: > nodemon app.js
Feb 28 01:17:45 ip-172-31-47-138 web: sh: nodemon: command not found
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! code ELIFECYCLE
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! syscall spawn
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! file sh
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! errno ENOENT
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! [email protected] start: `nodemon app.js`
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! spawn ENOENT
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR!
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! Failed at the [email protected] start script.
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR! A complete log of this run can be found in:
Feb 28 01:17:45 ip-172-31-47-138 web: npm ERR!     /home/webapp/.npm/_logs/2022-02-28T01_17_45_707Z-debug.log
Feb 28 01:17:46 ip-172-31-47-138 web: > [email protected] start /var/app/current
Feb 28 01:17:46 ip-172-31-47-138 web: > nodemon app.js
Feb 28 01:17:46 ip-172-31-47-138 web: sh: nodemon: command not found
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! code ELIFECYCLE
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! syscall spawn
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! file sh
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! errno ENOENT
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! [email protected] start: `nodemon app.js`
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! spawn ENOENT
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR!
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! Failed at the [email protected] start script.
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! A complete log of this run can be found in:
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR!     /home/webapp/.npm/_logs/2022-02-28T01_17_46_218Z-debug.log
Feb 28 01:17:46 ip-172-31-47-138 web: > [email protected] start /var/app/current
Feb 28 01:17:46 ip-172-31-47-138 web: > nodemon app.js
Feb 28 01:17:46 ip-172-31-47-138 web: sh: nodemon: command not found
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! code ELIFECYCLE
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! syscall spawn
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! file sh
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! errno ENOENT
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! [email protected] start: `nodemon app.js`
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! spawn ENOENT
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR!
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! Failed at the [email protected] start script.
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR! A complete log of this run can be found in:
Feb 28 01:17:46 ip-172-31-47-138 web: npm ERR!     /home/webapp/.npm/_logs/2022-02-28T01_17_46_718Z-debug.log
Feb 28 01:17:47 ip-172-31-47-138 web: > [email protected] start /var/app/current
Feb 28 01:17:47 ip-172-31-47-138 web: > nodemon app.js
Feb 28 01:17:47 ip-172-31-47-138 web: sh: nodemon: command not found
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! code ELIFECYCLE
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! syscall spawn
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! file sh
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! errno ENOENT
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! [email protected] start: `nodemon app.js`
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! spawn ENOENT
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR!
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! Failed at the [email protected] start script.
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! A complete log of this run can be found in:
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR!     /home/webapp/.npm/_logs/2022-02-28T01_17_47_214Z-debug.log
Feb 28 01:17:47 ip-172-31-47-138 web: > [email protected] start /var/app/current
Feb 28 01:17:47 ip-172-31-47-138 web: > nodemon app.js
Feb 28 01:17:47 ip-172-31-47-138 web: sh: nodemon: command not found
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! code ELIFECYCLE
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! syscall spawn
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! file sh
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! errno ENOENT
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! [email protected] start: `nodemon app.js`
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! spawn ENOENT
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR!
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! Failed at the [email protected] start script.
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR! A complete log of this run can be found in:
Feb 28 01:17:47 ip-172-31-47-138 web: npm ERR!     /home/webapp/.npm/_logs/2022-02-28T01_17_47_715Z-debug.log


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source