CodeBlanks Logo Icon CodeBlanks

Module design

Design the skeleton of the helper library module.

Project: Helper library

In this 5-lesson project you will build a reusable helper library. Each lesson adds one piece, and by the final lesson you will have a working module. All helpers live inside one helpers object.

In Node.js the way to export a module is module.exports. When you write module.exports = helpers, the helpers object becomes available from other files with require. By grouping helpers in an object and exporting it, you create a toolkit usable anywhere in your application. Each lesson's starting code will contain the previous lesson's solution, so the library grows step by step.

The helpers object

First we define an empty helpers object. In the following lessons we will add methods to it. For now we prepare the skeleton and verify it works with console.log.

Example: const helpers = {}; defines the empty object. module.exports = helpers; exports it. console.log("Ready") shows the program runs. module.exports passes a reference, so methods added to helpers later also appear in the exported object. This is the key to growing the library piece by piece.

Practice Define the helpers skeleton

Define an empty object named helpers. Export it with module.exports. Print "Ready" with console.log.

Starter code

index.js
// Define the helpers object
// write here

// Export the module
// write here

// Print "Ready"
// write here

Sample solution

index.js
const helpers = {};
module.exports = helpers;
console.log("Ready");

Expected output

Hazır

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does module.exports do?

index.js
module.exports = helpers
  • helpers nesnesini siler
  • helpers nesnesini gizler
  • Exports the helpers object Correct answer
  • Renames the helpers object

Explanation: module.exports exposes helpers to other files.

2 Complete the export line

Question
module.exports = ____;
Answer
module.exports = helpers;

Explanation: The helpers object is exported.

3 Match each piece to its role

Term Meaning
const helpers = {} Defines an empty object
module.exports Exports
require Imports a module
console.log Prints output

All lessons in Intermediate