Using ES6 syntax “import/export” in Node js with Babel

Josephine Gyamera
3 min readAug 28, 2020
Background picture from Splash by Kevin Ku

Sometimes, it's difficult to understand how some setups are been done by other developers, especially for newbies like me. I struggled with setting up my Node js environment to use ES6 syntax. After several try and error, I finally got it.

If you try to run Node js app with ES6 syntax, you will encounter this kind of error

The error we are trying to solve

In this article, I will share with you how I set up my Node js environment with Babel. Before we get into it, I will briefly go over the dependencies we will be installing. Additionally, I will be using Nodemon in this tutorial.

Let’s get right into it!

In your terminal or console, you can run the following command.

npm init -y

Babel allows us to convert ES6(ECMAScript 2015+) codes(syntax) into backward-compatible versions of Javascript that can be run by older Javascript engines.

First of all, we will install three main packages.

npm install --save-dev @babel/core @babel/preset-env @babel/node

--

--