Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Beanstalk and ES6

I'm trying to deploy my node server on Elastic Beanstalk but it won't work because the latest version Elastic Beanstalk supports out of the box is 0.12.6 (July 2015). Using either io.js or the latest node version (4.1.2) are both viable options but it isn't clear how to get the ec2 instances spun up by beanstalk to do this.

I've tried a bunch of stuff including:

  1. adding the 4.1.2 source to my .ebextensions config file and then updating the reference in /tmp/deployment/config/#etc#init#nodejs.conf but console.log(process.argv) was still 0.12.6. What's more, the second time I run this I get some text file busy error presumably because it's trying to change the source of the node package while node is still running... (see https://forums.aws.amazon.com/thread.jspa?threadID=169385)
  2. adding a file that downloads the 4.1.2 source and ungzips it and updates the reference like in https://github.com/kopurando/better-faster-elastic-beanstalk but this didn't seem to work either (version still 0.12.6)

Why is it so hard to just run the latest stable version of node and something that has been widely supported for 4 months on AWS?

like image 470
Andrew Rasmussen Avatar asked Dec 19 '22 23:12

Andrew Rasmussen


1 Answers

Instead of using node v4, you can use babel to compile es6 code to es5 code and deploy es5 code to the beanstalk.

Let's say all your source codes are in lib directory with index.js file which start the server.

lib/
    index.js
    other

Then you can use babel lib -d dist to compile es6 files in lib directory and create es5 version of the files in dist directory.

dist/
    index.js
    other

Then you can just node dist/index.js to run your server and only need to change package.json as below for beanstalk since beanstalk uses npm start to run your server

"scripts": {
  "start": "node dist/index.js"
}

I like to use babel for es6 since it has more coverage on new features. You can find more information

node.js server example: https://github.com/babel/example-node-server

babel home page: https://babeljs.io/

like image 200
jryu Avatar answered Dec 28 '22 23:12

jryu