How to use ES6 in Node using Babel

Install Babel CLI

npm install --save-dev babel-cli

Add Presets

$ npm install --save-dev babel-preset-es2015 babel-preset-stage-2

Add .babelrc

"presets": ["es2015", "stage-2"]

Add ES6 code to index.js

Add start script in pakage.json

"start": "babel-node index.js"

Start server

npm start

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.