Using ES6 in nodeJS

Are you getting bored writing the ES5 code in nodeJS, then this is time to move to ES6. However node 6 has built in support for ES6, this post is meant for people using older versions of node.

  • Install babel-cli in your project
    npm install --save babel-cli
  • Install ES2015 presets for babel
    npm install --save babel-preset-es2015
  • If you want to compile your entire server code to distribution then you can use
    babel server/index.js -d output.js
    and then run
    node output.js
  • Else if you just want to run your code then use
    babel-node server/index.js
    This will automatically compile and run the es6 code for you.

Enjoy programming in ES6.

Advertisements