简体   繁体   English

错误:找不到模块“ ./models/user”

[英]Error: Cannot find module './models/user'

I'm doing the following tutorial: 我正在做以下教程:

https://www.raymondcamden.com/2017/02/08/using-social-login-with-passport-and-node/ https://www.raymondcamden.com/2017/02/08/using-social-login-with-passport-and-node/

but the code for the file: ./models/user referenced on the line: 但是文件代码: ./models/user引用:

var user = require('./models/user');

is not provided. 没有提供。

Then, I'm getting the error: 然后,我得到了错误:

Error: Cannot find module './models/user'

The variable: user is used on the following lines: 变量: user用于以下行:

var me = new user({
    email:profile.emails[0].value,
    name:profile.displayName
});

/* save if new */
user.findOne({email:me.email}, function(err, u) {
    if(!u) {
        me.save(function(err, me) {
            if(err) return done(err);
            done(null,me);
        });
    } else {
        console.log(u);
        done(null, u);
    }
});

But I have no idea about what should be the content of the file: ./models/user . 但是我不知道文件的内容应该是什么: ./models/user

Could you provide me some test content that makes this tutorial work? 您能否提供一些使本教程正常工作的测试内容?

Use this code on models/user file. 在模型/用户文件上使用此代码。

Just check it. 只是检查一下。

var mongoose=require("mongoose");
var passportlocalmongoose=require("passport-local-mongoose");
var UserSchema=mongoose.Schema({
    email: String,
    Password: String
});

UserSchema.plugin(passportlocalmongoose);
module.exports=mongoose.model("User", UserSchema);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM