Node.js modules creation usage

How to Create and Use Modules in Node.js

About how to create modules and use created modules in the Node.js programming language. In programming, we create external files, modules, and packages to aim for more readable and efficient coding based on the DRY principle (Don't repeat yourself).

Shou Arisaka
1 min read
Nov 13, 2025

About how to create modules and use created modules in the Node.js programming language. In programming, we create external files, modules, and packages to aim for more readable and efficient coding based on the DRY principle (Donโ€™t repeat yourself).

Image

Suppose you place tools.js in the same directory as follows:

cat > tools.js

module.exports = {
  hoge: function () {

            console.log('yy')

  }
};

Then you can call hoge() defined in tools.js as follows:

var tools = require('./tools');

tools.hoge() ; // #=> yy

Share this article

Shou Arisaka Nov 13, 2025

๐Ÿ”— Copy Links