I remember module.exports working perfectly fine once before but today It would'nt res.send. I simply receive a blank page with no errors. Could you explain why? I am quite confused. Here is an image of my directory structure if for some reason you need it: HERE!
Code(Important parts)
As you can see, I am attempting to get the test
variable in with the index.js
file. I required the file and put it out as an export.
App.js
var express = require('express');
var http = require('http');
var path = require('path');
var app = module.exports = express();
// all environments go here...
require('./routes/index.js');
//create server here
routes/index.js
var app = require('../app.js');
app.get('/testing', function(req,res) {
var logic = require('./logic.js');
res.send(logic.test);
});
//other routes below
routes/logic.js
var test = module.exports = "Hello World";
You are using module.exports
in a wrong way to achieve your result. Try:
module.exports.test = "Hello world";
test
should be a property of module.exports
object if you want to use module.test
afterwards