gpt4 book ai didi

javascript - 错误: Cannot find module './server/controllers/meetups-controller'

转载 作者:行者123 更新时间:2023-12-03 05:36:15 27 4
gpt4 key购买 nike

我的平均应用程序出现问题,出现错误:找不到模块“./server/controllers/meetups-controller”。该文件位于正确的目录中,但我收到错误,请帮助

这是我的服务器代码:

var express = require('express');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var expressSession = require('express-session');
var mongoose = require('mongoose');
var hash = require('bcrypt-nodejs');
var path = require('path');
var passport = require('passport');
var localStrategy = require('passport-local' ).Strategy;
var meetupsController = require('./server/controllers/meetups-controller.js');
// mongoose
mongoose.connect('mongodb://localhost/mean-auth');

// user schema/model
var User = require('./models/user.js');

// create instance of express
var app = express();

// require routes
var routes = require('./routes/api.js');

// define middleware
app.use(express.static(path.join(__dirname, '../client')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('express-session')({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));

// configure passport
passport.use(new localStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

// routes
app.use('/user/', routes);

app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, '../client', 'index.html'));
});

// error hndlers
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

app.use(function(err, req, res) {
res.status(err.status || 500);
res.end(JSON.stringify({
message: err.message,
error: {}
}));
});




app.use(bodyParser());
app.use('/js', express.static(__dirname + '/client/js'));

//REST API
app.get('/api/meetups', meetupsController.list);
app.post('/api/meetups', meetupsController.create);
module.exports = app;

最佳答案

不确定,但可能您不需要明确提及文件扩展名。

未经测试,但您可以尝试删除 js 部分

var meetupsController = require('./server/controllers/meetups-controller');

关于javascript - 错误: Cannot find module './server/controllers/meetups-controller' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40725073/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com