Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  3] [ 1]  / answers: 1 / hits: 28813  / 8 Years ago, tue, april 5, 2016, 12:00:00

I have the latest NodeJS installed and for any JavaScript files, I can execute it with node myscript.js but recently I'm learning es6 and for some of the latest syntax, it just pop out some errors/exceptions while executing. I tried babel-cli, but didn't seem to work as it is for compile es6 to 5 not for command line execute.


More From » node.js

 Answers
26

1) To enable the support of ES6, use the --harmony flag:



node --harmony myscript.js


This will enable the available ES6 syntax in node. But notice it's currently a limited subset of the ES6 standard (see the compatibility table).



2) To have a complete compatibility, you have to use babel node.

Install @babel/node to get a babel-node executable which works exactly the same as Node.js's CLI, only it will compile ES6 code before running it.



babel-node myscript.js

[#62691] Saturday, April 2, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anikas

Total Points: 258
Total Questions: 102
Total Answers: 95

Location: Monaco
Member since Sun, Jan 16, 2022
2 Years ago
anikas questions
;