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 ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.