I wanted to host 2 node app on one Linux box from AWS EC2. Where I can run a dev environment and staging environment. I noticed that I will have to use different ports on both of the apps but this is not the problem that I am facing.
Using the staging side which has always worked on the previous boxes that I have started it on to go first, making sure it works before trying out the different ports.
I have a backend node.js using express and a static webpage built with Vue CLI. Where the express app will use app.use(express.static('static'));
to host the static webpage. Then proceed with hosting it on PM2 with pm2 start /directoryToDist/main.js
. Once the daemon has started, I did a curl http://localhost:80/
but it returns an error HTML page of Cannot GET /
.
When I did npm install
, npm rebuild
and npm build
on both apps. Made sure that the dist
folder was built properly. Then did a sudo -i
and pm2 start /directoryToDist/main.js
. Making sure that a node app is running I did a ps -ef | grep js
to show that it is running as so. There are no restarts on the pm2 mounted app and everything was running smoothly. I did the curl http://localhost/
after and it did return Cannot GET /
.
I did a zip file transfer of a working app in previous boxes and did the necessary installation of npm and run it. Expecting it to work like previous boxes but it didn't. showing the same error of Cannot GET /
.
Node js build script
"build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./babelrc,./package.json,/.npm-debug-log,./static/* --copy-files"
Vue js build script
"build": "node build/build.js"
Rebuild script that I use
cd api
npm run build
cd ..
cd pwa
npm run build
cd ..
sudo rm -rf api/dist/static
sudo mkdir -p api/dist/static
sudo cp -r pwa/dist/* api/dist/static/
sudo chown -R ubuntu.ubuntu *
Let me know if you need to see more
The actual result is to serve a proper 200
message on the curl before given a domain to the specific port.
ROOT/dist/static/*.*
? – Matt Oestreich/home/ubuntu/nodeApp/dist/main.js
inside the main.js has aapp.use(express.static('static'))
that serves index.html – Yikernapp.use(express.static('dist'))
in that case.. depending upon where your entry point is located for the Node app.. – Matt Oestreichpackages.json
file look like? Specifically "main"? – Matt OestreichnodeApp
has adist
folder that has all the built files and then putting the built files of thestatic nodeApp
front end side of it onto static subdirectory ofnodeApp
'sdist
and run the main.js app on it. – Yikern