Module in NodeJS and ES6

Aussie Developer
Jul 28, 2017 · 1 min read

Modules are frequently used techniques which is an important part of decoupling and make the code more readable and organised.

Module in NodeJS

In NodeJS, keywords module, exports and required are exploited to create/import a module. Here are three ways of creating a module. Some examples:


Module in ES6

In ES6, we can export constant, function, class as modules:

  • export constant
  • export function
  • export class

However, import keyword is from ES6, but not natively supported by NodeJS yet, so in order to make the following code work, we use babel to compile it first.


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade