/dev tips

🎊   The Modern DevTools course has now started! Visit ModernDevTools.com to find out more   🎊

(38) Scroll into view Open resources from the Elements panel into the Sources Panel (40)

Node.js: Use Babel to run ES6 JavaScript

20 May 2015
Use Babel to run ES6 JavaScript

It's quick to try out ES6 style code in JavaScript. In your terminal:

npm install -g babel

Create a new file sum.js:

const sum = arr => arr.reduce((a, b) => a + b);
console.log( 'sum: ', sum([1,2,3]) )

Then run: babel-node sum.js

You can even run babel-node without any arguments and use the REPL to execute JS on the fly. If you introduce it into a project, there are babel packages for Gulp and Grunt.

Sign up to receive a developer tip, in the form of a gif, in your inbox each week.