chevron-up bell reply instagram twitter2 feed3 finder search-25px-p0

Module in NodeJS and ES6

2017-07-28

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.


Reference

http://www.arkilis.me

arkilis

Comments: