Install the Babel CLI and a preset

npm install --save-dev babel-cli babel-preset-env

Create a .babelrc file (or use your package.json)

{ "presets": ["env"] }


Now we can test that is working by creating a normal js file to require and put some ES2015 code inside of it. Don’t worry about what all this code does right now, I’ll go over the features of ES2015 in detail shortly.

function test1(foo, ...args) {

    let [bar, baz] = args;

    for(let arg of args) {

        let bar = 22;

        console.log(`arg: ${arg} bar: ${bar}`);


    console.log(`done: ${bar} :: ${baz}`);


module.exports = test1;

Then save that as test1.js and we can create another js file onthefly.js to load it.



var test = require('./test1.js');


test('aa', 'b', 22, 43);

// arg: b bar: 22

// arg: 22 bar: 22

// arg: 43 bar: 22

// done: b :: 22