If i have schema.js in the same folder as index.js doing something like
var schemas = require('./schema');
works fine, but if i put the schema.js in another folder and write
var schemas = require('./folder/schema');
i get an error Cannot find module whats happening?
Edit1 : I got rid of the error by using ..folder/schema instead of single. and the server runs but it still doesn't work properly as I cant use the mongoosedb object returned through module.export from ../model/schema in the index.js file. It says myModel.find is not a function. Whats going on??
controllers/findallusers.js
var myModel = require('../models/schema');
var alluser;
myModel.find({}, function(err, foundData){
if(err){
console.log(err);
res.status(500).send();
}
else{
alluser = foundData;
}
console.log(alluser); <-- this log is defined
});
console.log(alluser); <-- this log is undefined
module.exports = alluser; <-- cant export anything
folderdirectory in the same directory as the index.js file?module.exportin schema,js and trying to use it in index.js byvar schemas = require('./model/schema');.find()is asynchronous. Therefore IT IS IMPOSSIBLE to return it via module.exports. Instead, export a function that accept a callback or return a promise.list : funtion(req, res){ }but getting syntax error atlist: function(req, res) {whats going on?