Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy on AWS ElasticBeanstalk - run custom npm script before starting server?

I have been trying to deploy my nuxt universal app onto AWS elastic beanstalk. I've tried using custom npm script in my package.json:

"scripts": {
 "dev": "nuxt",
 "build": "nuxt build",
 "start": "nuxt start",
 "generate": "nuxt generate",
 "precommit": "npm run lint",
 "deploy": "nuxt build && nuxt start"
},

Then under AWS EB config, i added Node command: npm run deploy

However, it is not working.

Basically, i need to tell EB to run "npm run build" before "npm run start"

Anybody can help?

like image 583
wayfinder Avatar asked Oct 16 '22 15:10

wayfinder


2 Answers

What you've described lies in the npm realm, and can be solved by using a prestart script, like so:

"prestart": "nuxt build"

More details here: https://docs.npmjs.com/misc/scripts

like image 169
Kunal Nagpal Avatar answered Oct 30 '22 18:10

Kunal Nagpal


So far this has helped me, it seems to work for default nuxt project (nuxt create) in universal mode. I am using Elastic Beanstalk, CodePipeline and Bitbucket. CodePipeline takes code from Bitbucket once it is pushed and builds in on Elastic Beanstalk.

What helped me is adding to package.json:

"deploy": "npm run build && npm run start"

or

 "deploy": "npm run install && npm run build && npm run start"

and creating Procfile in root directory of project, content/command of Pocfile triggers the deploy script in package.json file

web: npm run deploy
like image 42
atazmin Avatar answered Oct 30 '22 17:10

atazmin