表示不在单独的模块中调用回调

时间:2017-07-30 16:56:38

标签: javascript node.js

当尝试调用results.js回调时,它将不会执行。 showDate函数将执行并编写console.log。调试时似乎可以解决路由功能。

然而,当从search.ejs发布到页面时,它将为路径提供404。

app.js

var express = require("express");
var session = require('express-session');
var bodyParser = require('body-parser');

var app = express();
//MongoDB
var mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/time_report");

var userSchema = new mongoose.Schema({
    name: String,
    password: String
});


var user = mongoose.model("user", userSchema);
module.exports = {
    app: express(),
    user
};

var resultJS = require("./results.js");
resultJS.showDate();

results.js

var test = require("./app.js");

function showDate() {
console.log("showDate"); // Will execute on application startup
    test.app.post("/results", function(req, res) {
        res.render("results"); //Not executing

    //Get login info
    var uName = req.query.username;
    var pw = req.query.password;

});
}

module.exports.showDate = showDate;

0 个答案:

没有答案