I am using nodejs only for server side microservices, I want to use ES6, I have read that Babel is used to transpile code to ES5 to provide support for browsers. So I need to know if I am not writing this code for client side would I still need to transpile it to run it on V8 engine? Or is it just an extra layer which won't be needed on server side?
I am using nodejs only for server side microservices, I want to use ES6, I have read that Babel is used to transpile code to ES5 to provide support for browsers. So I need to know if I am not writing this code for client side would I still need to transpile it to run it on V8 engine? Or is it just an extra layer which won't be needed on server side?
Share Improve this question asked Sep 27, 2017 at 6:37 TGWTGW 83511 silver badges29 bronze badges 2- No using ES7 is probably the way to go. Why would you speak spanish with your neighbour if both can speak english natively? – Jonas Wilms Commented Sep 27, 2017 at 6:49
- If you're using ES modules (which are ES6), you still need to transpile. Also, the thing you're calling 'ES6' may contain features that are naturally transpiled by Babel but aren't supported by Node/V8. – Estus Flask Commented Sep 27, 2017 at 7:03
4 Answers
Reset to default 4You need to use a transpiler if your runtime doesn't support the language features you are using.
The latest version of Node.js has almost plete support for ES6.
If you use features unsupported by whatever version of Node.js you are using, you will need to use a transpiler.
If your server works on the new versions of Node.js and it supports ES6 features, you don't need to transpile your code. Your code only works in the same place, if it is hosted in one place.
Transpiler is used, when your code is written in newer versions, there may be users which use browsers with old versions of Javascript. So the browser need to get the JS code from the hosted place and run locally, here may be errors. In this case you need to use transpiler.
If you are only using the code as a microservice, you don't need to do transpiling. All latest versions of Node.js support es6 by default. You can refer here for more information of what es6 features are currently supported by Node
Node.js es6 documentation
I suggest ues es6/es7 directly in the latest nodejs. Now the latest nodejs almost support most functions except import/export.
If so, you can use arrow function, async await etc.. which can make your code more clear.