Created
October 13, 2018 02:25
-
-
Save rparsi/ee89e376ed655146f6d21d0eadedc63e to your computer and use it in GitHub Desktop.
Nodejs custom modules with native Nodejs module syntax: example 01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Assumptions | |
| ================================== | |
| Working directory structure: | |
| ./lib/Console.js | |
| ./App.js | |
| /* in ./lib/Console.js */ | |
| "use strict"; | |
| class Console | |
| { | |
| constructor() { | |
| this.version = '1.0.0'; | |
| } | |
| print(message) { | |
| console.log(message); | |
| } | |
| toString() { | |
| return `Console: ${this.version}`; | |
| } | |
| } | |
| module.exports.Console = Console; | |
| /* in ./App.js */ | |
| "use strict"; | |
| let ConsoleModule = require('./lib/Console'); | |
| let Console = ConsoleModule.Console; | |
| let console = new Console(); | |
| console.print(console.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment