Using Babel CLI to transpile our code
Now, let's use the Babel CLI to transpile our code:
$ npx babel index.js -o compiled.js
The preceding command uses npx, a tool that was introduced with npm v5.2.0. npx allows you to run binaries install locally (within your project's node_modules directory, as opposed to globally) using a very tidy syntax. Instead of typing ./node_modules/.bin/babel index.js -o compile.js, you can shorten it to npx babel index.js -o compile.js.
Here, we are using npx to run the local babel executable, which will transpile our index.js file and output it as compiled.js.
If you compare the two files, you'll see that apart from formatting changes (such as whitespace), the two files should be identical. This is because the Babel CLI, by default, will simply copy files from one place to another. To give it functionality, we must add plugins and specify them in a configuration file. So next, let's create that configuration file. At the root of the project directory, create a new file named .babelrc and add the following lines:
{
"presets": [],
"plugins": []
}