How to write Javascript in ES6 with Nodejs

You building an application with React and Node. You write your React code in ES6 but when you visit your Node backend code you happen to write in ES5. I found this quite annoying due to the change and also the require method. If you feel you are comfortable writing ES5 Node, you can skip this blog but if you might like making your frontend and backend switch quite seamless as we wait to figure out deno, you are in luck, because I will guide you in all the steps you will have to undertake and I have an existing NodeJS ES6 template setup already on Github.

Prerequisites

Basic knowledge of writing JS in ES6 standard

Basic expressjs concepts

Let's get started

The usual stuff, create a new folder to house our code and change directory to the folder.

$ mkdir node_api_es6_template && cd$_

Create a package.json file to track our dependencies

$ yarn init -y
// or
$ npm init -y

Use whichever command, you feel comfortable with but throughout this project I will use yarn, I always feel its like npm but on steroids.

We will have to install a couple of babel packages to transpile our ES6 code to ES5