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

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

in the file newmodule.js, add this code: = "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:


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


Leave a Comment