admin管理员组

文章数量:1312791

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 .jspa?threadID=169385)
  2. adding a file that downloads the 4.1.2 source and ungzips it and updates the reference like in 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?

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./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./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?

Share Improve this question edited Mar 12, 2016 at 1:41 Clarkie 7,5509 gold badges40 silver badges53 bronze badges asked Oct 7, 2015 at 0:04 Andrew RasmussenAndrew Rasmussen 15.1k10 gold badges47 silver badges84 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

Instead of using node v4, you can use babel to pile 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 pile 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./babel/example-node-server

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

One option is to create a custom AMI (Amazon Machine Image) and use that to deploy your app:

http://docs.aws.amazon./elasticbeanstalk/latest/dg/using-features.customenv.html

There's loads of steps in their documentation but in simple terms you need to:

  1. spin up a server
  2. customise the installations however you wish
  3. create an image
  4. create an elastic beanstalk environment using your newly created AMI

Another option if you want to run node with ES2015 features is to use the babel cli.

You'll need to add a start task to your package.json:

{
  "scripts": {
    "start": "babel-node index.js",
  },
  "dependencies": {
    "babel": "^5.8.23",
  }
}

However...

Not meant for production use

You should not be using babel-node in production. It is unnecessarily heavy, with high memory usage due to the cache being stored in memory. You will also always experience a startup performance penalty as the entire app needs to be piled on the fly.

本文标签: javascriptElastic Beanstalk and ES6Stack Overflow