I’m trying to deploy a very basic angular app to elastic beanstalk. The project was created using the angular cli. I have not made any changes to the files in this project.
Here are the steps I took to deploy the app
I always end up with a ‘npm install failed’ error when I check eb-activity.log.
Am I missing something trivial here? Would really appreciate any help with deploying angular apps to EB.
Follow the steps:
-- Angular app
ng build --prod
commandThe angular app you just built won’t work as a static website, it has to run on top of a Node.js server
-- Node.js App
npm init
and follow the instructionsnpm install express path --save
commandvar path = require('path'); const port = process.env.PORT ||3000; const app = express(); //Set the base path to the angular-test dist folder app.use(express.static(path.join(__dirname, 'dist/yourappfolder'))); //Any routes will be redirected to the angular app app.get('*', function(req, res) { res.sendFile(path.join(__dirname, 'dist/yourappfolder/index.html')); }); //Starting server on port 8081 app.listen(port, () => { console.log('Server started!'); console.log(port); });
Hope this is useful!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With