Do we really need babel for NodeJS application

Sairam Krish
Aug 22, 2017 · 2 min read

At this point we all know that NodeJs support for latest Ecmascript is growing rapidly and Babel is an awesome library to transpile Javascript. Many projects use Babel for client side transpiling and many use babel for server side (NodeJs) javascript transpiling.

Every new release of NodeJS support more and more ES6/7 features. Please have a look at node.green for Javascript compatibility metrics.

Following data taken for reference from node.green

If NodeJs is offering better ecmascript support out of the box, why do we need babel-node.

Major feature that we may miss:

  • Import/export -> instead we need to use require() and module.exports

We are able to get most of ES6/7 quality code without babel.

Consolidated here some well written / detailed explanation on this area:

Quick tips

if you have lot of existing javascript files that has import statements. This regular expression to search

import\s+(\w+)\s+from\s+\’([^’]+)’\;?

and replace:

const $1 = require(‘$2’);


If you use using OOPS concepts and have classes in your application, we may need to change the exports like below, which is little tricky:

When you assigned this:

exports.MyCustomer = MyCustomer;

You would need to match that with this:

var MyCustomer = require('/path/to/file').MyCustomer;

other way, you could change to this:

exports = MyCustomer;

And, then your require() could work the way you are doing it like this:

var MyCustomer = require('/path/to/file')

)

Sairam Krish

Written by

Software Architect ★ Full stack developer ★ Data management enthusiast — Document | KeyValue | RDBMS

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade