How to write a module in Node.js

In this tutorial I will explain how to write a simple module in Node.js.

First, you must install Node.js from here https://nodejs.org/

Create  a folder on your desktop, and create two files(app.js and newmodule.js).

in the file newmodule.js, add this code:

exports.info = "Hello World!";

This code will display  Hello World!

Now, in the file app.js, we need to include the new module:

var newmodule = require("./newmodule.js");

And, to view the output, we need to add:

console.log(newmodule.info);

Open the command line from your created folder, and enter node app.js

Video:









Leave a Comment