Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences using es6 on nodejs vs babel

im currently learning a making a doc about ES6, i see that both nodejs and babel, are ways to work with the new es6 features and syntax, but, what are the real differences ?

like image 452
Felipe Quirós Avatar asked Feb 23 '17 22:02

Felipe Quirós


3 Answers

Babel is a transpilation library. It takes ES6/7/Next code and compiles it down to a previous standard. It allows you to use ES6, some of ES7 and with plugins, things that are not officially part of the language yet. Babel is usually used to transform ES6+ code so that it can be run in a browser, many of which that are still in wide use only support ES5.

Node is a server-side javascript runtime, while you can use node to run babel'd code (it's just javascript!), you don't need to as node can understand ES6 on its own.

The basic answer to "Which should I use?" is Babel in the browser, Node on the server.

like image 104
Joe Ruello Avatar answered Sep 30 '22 13:09

Joe Ruello


  1. nodejs is a javascript runtime environment, built upon Chrome's V8 engine. It understand modern javascript natively.
  2. babel is a polyfill library that allow older browsers (or even older version of nodejs) to run modern javascript syntax (ES6) by "translating" newer syntax into their older equivalent.
like image 22
AVAVT Avatar answered Sep 30 '22 14:09

AVAVT


  1. Babel can be used to make es6 code work on browsers that don't support es6 as much as node does,
  2. Not every project supports the latest version of Node, Babel can compile code such that it works on older Node versions
like image 38
lonewarrior556 Avatar answered Sep 30 '22 13:09

lonewarrior556