gpt4 book ai didi

javascript - 平均堆栈 :ReferenceError:

转载 作者:行者123 更新时间:2023-11-29 23:20:21 25 4
gpt4 key购买 nike

我创建了一个名为 jobslist.js 的模式

 var mongoose = require('mongoose');
var Schema = mongoose.Schema;


var jobListSchema = new Schema({
companyName: String,
jobtitle: String,
location: String
});

var joblist = mongoose.model('jobList', jobListSchema);

module.exports = joblist;

这是我的路由文件 user.js

    const jobList = require('../models/joblist');
router.post('/appliedjobs', function(req,res) {
console.log('posting applied jobs list');
var appliedjob = new jobList();
appliedjob.companyName = req.body.companyName;
appliedjob.jobtitle = req.body.jobtitle;
appliedjob.location = req.body.location;
console.log(appliedjob);
appliedjob.save(function(err,joblist) {
if(err) {
console.log(err);
} else {
res.json({msg: 'job is saved'});
}
});
});

//get applied job list
router.get('/appliedjobs',function(req,res ) {
console.log('getting applied jobs');
appliedjob.find(function(err, appjobs) {
if (err) {
console.log('unable to get jobs '+ err);
} else {
console.log('getting list');
res.json(appjobs);
}
});
});

我收到错误信息

获取工作得到应聘的工作

ReferenceError: appliedjob is not defined at D:\product\project-1\routes\users.js:132:3 at Layer.handle [as handle_request] (D:\product\project-1\node_modules\express\lib\router\layer.js:95:5) at next (D:\product\project-1\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\product\project-1\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (D:\product\project-1\node_modules\express\lib\router\layer.js:95:5) at D:\product\project-1\node_modules\express\lib\router\index.js:281:22 at Function.process_params (D:\product\project-1\node_modules\express\lib\router\index.js:335:12) at next (D:\product\project-1\node_modules\express\lib\router\index.js:275:10) at D:\product\project-1\routes\users.js:15:3 at Layer.handle [as handle_request] (D:\product\project-1\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (D:\product\project-1\node_modules\express\lib\router\index.js:317:13) at D:\product\project-1\node_modules\express\lib\router\index.js:284:7 at Function.process_params (D:\product\project-1\node_modules\express\lib\router\index.js:335:12) at next (D:\product\project-1\node_modules\express\lib\router\index.js:275:10) at Function.handle (D:\product\project-1\node_modules\express\lib\router\index.js:174:3) at router (D:\product\project-1\node_modules\express\lib\router\index.js:47:12)

我检查了我的数据库(MongoDB),没有生成集合。

最佳答案

你应该修改 jobslist.js 文件的最后一行。

下面是正确导出mongoose模型。

module.exports = { jobList : mongoose.model('jobList', jobListSchema) };

导入时改变第一行

var JobList = require('../models/jobslist').jobList;

关于javascript - 平均堆栈 :ReferenceError:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50942379/

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