Tuesday, April 24, 2018

How to create a simple module

1- Create a file called my-module.js
2- Add the following code:

exports.myText = 'this is a test'

3- Save changes
4- Create a file called module-demo.js
5- Add the following code:

var mDemo = import('.\my-module.js)

console.log(mDemo.myText)

6- Execute in console:

node .\module-demo.js

7- Console output will be

this is a test

No comments:

Post a Comment