-1

So I created a module for node js and connected it to the main file, then ran the server in localhost:8080. The code ran but, this happened-

display of localhost:8080

this is the code for the main node.js file-

var http = require('http');
var dt = require('./demo_module.js');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.write("Date and time:" + dt.myDateTime)
  res.end('Hello World!');
}}.listen(8080;)

The code for module-

exports.myDateTime = function () {
return Date();
};

1 Answers1

1

This is a function, you need to call it otherwise it will just print the function

exports.myDateTime = function () {
  return Date();
};

Change to this:

res.write("Date and time:" + dt.myDateTime());
Hive7
  • 3,599
  • 2
  • 22
  • 38