【发布时间】:2021-05-16 18:30:41
【问题描述】:
所以我为node js创建了一个模块并将其连接到主文件,然后在localhost:8080中运行服务器。代码运行了,但是发生了这种情况-
这是主 node.js 文件的代码-
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;)
模块代码-
exports.myDateTime = function () {
return Date();
};
【问题讨论】:
-
"display of localhost:8080" 是所发生的截图的链接
-
res.write("Date and time:" + dt.myDateTime)-> 你需要实际调用你的函数:dt.myDateTime() -
你没有调用函数
标签: javascript node.js