How would I run or execute a code in ES6 using the Babel engine or module in Node Js, without trans-piling it to ES5.
Asked
Active
Viewed 1,364 times
-1
-
2It's not clear what you're asking. As best I know, you don't run code in Babel at all. It's a transpiler not a JS runtime environment. You run ES6 code in node.js by just running the non-transpiled code directly in node.js since it natively supports ES6 already. You'd use a command line `node myscript.js` to run that script file. You don't use Babel at all to run ES6 code in node.js. – jfriend00 Feb 24 '20 at 06:57
-
My project has Babel configured in it and it is running by default, now I don't want to transpile my ES6 code to ES5. I just wanted to ask that, is it possible not to transpile the ES6 code to ES5 even if my code has Babel configured in it and running automatically. – user6819864 Feb 24 '20 at 07:11
-
@user6819864, check my answer, directly run int with node yourfile.js – Juhil Somaiya Feb 24 '20 at 07:14
2 Answers
1
Node JS and browsers support ES6. But for using additional features you have to first configure babel with .babelrc and also add npm scripts for building your project to ES5, then run it with node js or browser.

Hamed Navabian
- 720
- 7
- 11
-
Uhh, node.js supports ES6 directly so there is NO need to transpile ES6 code to ES5 in order to run it in node.js. In fact, Babel is completely unnecessary to run ES6 code in node.js. – jfriend00 Feb 24 '20 at 07:06
-
My project has Babel configured in it and it is running by default, now I don't want to transpile my ES6 code to ES5. I just wanted to ask that, is it possible not to transpile the ES6 code to ES5 even if my code has Babel configured in it and running automatically. – user6819864 Feb 24 '20 at 07:08
-
@user6819864 - Remove babel from the configuration and run your source file directly. YOU have to fix your configuration to stop using babel if you want to run ES6 code directly. – jfriend00 Feb 24 '20 at 07:23
-
without babel, you can not use import and export es6 features @jfriend00 – Hamed Navabian Feb 24 '20 at 07:40
-
First off, `import` is not part of ES6 (it came later). Second, node.js already supports `import` natively. Third, node.js supports ES6 features already and has for sometime. Look [here](https://node.green/#ES2015) to see. ES6 === ES2015. – jfriend00 Feb 24 '20 at 08:03
0
As per my understanding, we don't use Babel for running a code. In simple words it is a transpiler that converts the modern ES2015/ES6 code to the browser understandable js code, while now a days most of the browser supports ES6.
Node.js is a js run-time where you can run your javascript file and which natively supports ES6 implementation.
You can directly run your script file using node command as below, you don't require transpiler/Babel to run it.
node yourScript.js

Juhil Somaiya
- 873
- 7
- 20
-
The project I am working on had Babel configured in it already. Now the thing is I don't want to transpile the code in ES5, also I can't make chances in Babel config. – user6819864 Feb 24 '20 at 07:14
-
The thing is I can't show the json file, as it would be against the TnC of the client and the company I am working in. Hope you may understand. – user6819864 Feb 24 '20 at 07:18
-
-