Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can node.js and JS Frameworks make use of ES6 out of the box?

I read that ES6 was released as and a lot of web browsers support it, I want to now if I can use ES6 features and syntax out of the box in the newest version of node.js and js frameworks like angular.js or react.js ?

like image 989
Jose Osorio Avatar asked Nov 21 '25 02:11

Jose Osorio


2 Answers

Yes, Node/IO.js can use ES6 out of the box, but support is still limited today. As Felix King noted, you can check the partial support at:

http://kangax.github.io/compat-table/es6

To enable ES6 features in Node.js you can run node with the harmony argument, but be aware that it enables both stable and unstable features:

node --harmony app.js

If you use IO.js most stable ES6 features are included by default, however they also have the harmony argument that enables additional staging and in progress features of ES6, so bottom line is that IO.js gives you stable ES6 support out of the box, but you can get additional stuff using the harmony argument.

iojs --harmony app.js

https://iojs.org/en/es6.html

Since the ES6 support in Node/IO.js is still partial, to get full ES6 support in Node you should use a Transpiler.

For Angular and React, to get ES6 support for the main stuff (classes, arrow funcs etc.) across all browsers you must use a Transpiler, and you have many many options. Some of the most popular are TypeScript, Babel, and Traceur.

There are many differences between these, and it depends on what you want. If you want pure ES6/ES7 support, i would go with Babel. If you want optional types and additional features (e.g. Generics) you should go with TypeScript.

However, Babel has the best tooling today, and i would stick to it for both front-end (Angular/React) and backend (Node).

https://babeljs.io/

If you are interested to read more about the need for Transpilers read:

http://www.ministryofprogramming.com/typescript-is-the-new-javascript/

like image 167
Faris Zacina Avatar answered Nov 23 '25 15:11

Faris Zacina


Right now you need to use something to compile your ES6 to ES5. For example this: https://babeljs.io/.

Here is a seed (without docs yet) that uses babeljs.

https://github.com/ottogiron/node-hapi-seed

With that you can write ES6 and feel like you are using it "out of the box".

like image 25
Gepser Hoil Avatar answered Nov 23 '25 16:11

Gepser Hoil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!