Reputation: 141
I have problem with my app, the files' tree is:
myApp
controllers
cars.js
models
car.js
app.js
package.json
in my code I call my model and mi controller of the next way...
var express = require('express');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var methodOverride = require("method-override");
var app = express();
...
**var models = require('./models/car')(app, mongoose);**
**var CarCtrl = require('./controllers/cars');**
but, not working it.. I have the next error:
Error: Cannot find module 'controllers/cars'
Error: Cannot find module 'models/car'
anything idea? thank you.
Upvotes: 1
Views: 1774
Reputation: 86
Check both car and cars.js. If you require app.js in any of them, you created a chain dependency, which Node.js throws this exact error, that you can't find a module.
Upvotes: 1
Reputation:
Try going to the root first. require('../myApp/controllers/cars'); If this didn't work, try console logging the path. Hope this works
Upvotes: 1