ES6 on Node.js (And Heroku)

I will get straight to the point. ES6 is awesome and we want to use it in our Node.js project. We would use Babel to convert ES6 codes to ES5 compatible Javascript for Node. We first install Babel.

Now we write our awesome app in ES6:

We could use Babel to transpile ES6 to ES5 and then run the ES5 code in Node. But instead we shall directly run ES6 with the “babel-node” binary. The babel-node binary transpiles ES6 code in runtime. So we don’t need any watchers or manual transpilation.

We modify our package.json’s script’s section to add the babel-node binary:

Now if we push to Heroku, it will work fine 🙂


5 Comments ES6 on Node.js (And Heroku)

  1. Jason

    For me I needed to use babel-node.js rather than simply babel-node, e.g.

    "start": "./node_modules/babel/bin/babel-node.js index"

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *