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.
Try going to the root first. require('../myApp/controllers/cars'); If this didn't work, try console logging the path. Hope this works
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.