Using ES6 directly in command line

As per this post node (version 10.6) is still not fully applying es6 features, anyway you can check it in here for the implementations, but if you not too patient waiting for it the solution is using Babel, but the question is how we treat babel as we execute js script normally using node (cli) ?, the answer is as follow.

  • Install following library. (you can adjust it whether you want set as global using argument -g).
npm i babel-cli babel-preset-es2015
  • We set es2015 in list of babel's preset.
echo '{"presets": ["es2015"]}' > .babelrc
  • Create a symbolic link for babel-cli executor script, es6 is just an example.
ln -s ./node_modules/babel-cli/bin/babel-node.js es6
  • Make a testing script to proof we can use some of unsupported feature from current nodejs.
echo "import fs from 'fs';" > halo.js
  • Execute it
./es6 halo.js


Popular posts from this blog

Disable sending telemetry data in DotNet

Running debug SMTP server with python