How to use ES6+ with Node.JS

I have seriously come to really like the new features that come with ES6+ Javascript such as async/await, the new class syntax, let and const (screw you hoisting!), arrow functions, destructuring, the new import syntax, and many more. These features are seriously useful. I think that the import syntax in particular makes Node.JS feel so much more like it was made for Javascript.

Ok. Ok. I’ll get on with it—How can I use ES6+ with Node.JS? It’s super simple.

1. cd to your project in your Terminal

2. Run npm install --save-dev esm

3. Run your main Javascript file with node -r esm {THE FILE}

If you are using nodemon, you can just run nodemon -r esm {THE FILE}.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *