The Road to Node.js ES6

Sami Ayed
Sami Ayed
Dec 12, 2016 · 2 min read

So you’re interested in writing up some ES6 on your server-side NodeJS project? awesome! you’re in the right place.

Node.js ES6 Support

Node.js follows a release plan, and currently v5 is not supported anymore, which leaves us with v4 on a Long Term Support (LTS) until 2018, and v6 a couple of years later.

Image for post
Image for post

Node.js v6 has received updates recently which now makes it 99% compatible with ES6. This can be easily monitored with node.green, which if you haven’t heard of, then here’s how it looks like:

Image for post
Image for post

So the go-to version now should probably be the latest v6 if you can afford it in your projects (dependencies issues and such).

Ensuring ES6 Support

It’s not easy for all projects to just upgrade to Node v6, so to make this transition process easier we’re going to add a transpiler called Babel, which is actually just a fancy way of saying “let’s use a tool that compiles our ES6 code to ES5 JavaScript which is supported well by older versions”.

Gulp will be used as a build process that compiles our source code with Babel, and saves it to a build folder.

Installing required libraries which are:

  • gulp itself
npm install --save gulp gulp-babel babel-preset-es2015

Compiling JavaScript with Gulp

Next up is to create the Gulp configuration which we will invoke in order to compile the code that we write in ES6 to the wider supported ES5 version of JavaScript.

gulpfile.js:

var gulp = require('gulp');
var babel = require('gulp-babel');
gulp.task('compile', function() {
return gulp.src('lib/*.js')
.pipe(babel({ presets: ['es2015'] }))
.pipe(gulp.dest('build'));
});

The gulp configuration is pretty straightfoward, we defined a task calledcompile that when run it will:

  • process all the .js files in the lib directory

That’s it!

You can now write ES6 in all of your source code files in the lib directory, and once you run gulp compile outside in the main project directory everything will be compiled into build.

You might want to change the gulp configuration to accomodate your project’s sources, directories, etc. Might also want to add gulp into your package.json scripts and build process.

Devagnos

Devagnos is specialized in web based solutions and mobile…

Sami Ayed

Written by

Sami Ayed

#Développeur, #Gameur, #Guitariste, #Bassiste, #Chanteur.. passionné quoi ..

Devagnos

Devagnos

Devagnos is specialized in web based solutions and mobile applications, we provide top of the edge solutions with the latest worldwide renowned technologies.

Sami Ayed

Written by

Sami Ayed

#Développeur, #Gameur, #Guitariste, #Bassiste, #Chanteur.. passionné quoi ..

Devagnos

Devagnos

Devagnos is specialized in web based solutions and mobile applications, we provide top of the edge solutions with the latest worldwide renowned technologies.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store