繁体   English   中英

模式猫鼬意外标识符

[英]schema mongoose unexpected identifier

当我使用nodejs运行此代码时,它在此行中向我返回此错误: “ SyntaxError:意外的标识符” ...

var user_schema =新架构({

  ^^^^^^^ 

我不知道这是什么问题...(对不起我的英语,我说西班牙语)

---------------- APP.JS CODE ------------------

var http = require("http");
var express = require("express");
var app = express();
var jade = require("jade");
var mongodb = require("mongodb");
var mongoose = require('mongoose');
var user = require("./public/js/users").user;
var bodyparser = require("body-parser");

app.set('view engine', 'jade');
mongoose.connect("mongodb://localhost/SoR");
app.use(express.static("public"));
app.use("/public",express.static("public"));
app.use(bodyparser.json());
//app.use(bodyparser.urlEncoded({extended: true}));

app.get("/login",function(req,res){
    res.render("login");
});

app.get("/",function(req,res){
    res.render("index");
});

app.get("/signup",function(req,res){
    res.render("signup");
});

app.post("/users",function(req,res){
    var user = new user({email: req.body.email, username: req.body.username, password: req.body.password});
    user.save(function(){
        console.log(req.body.email);
        console.log(req.body.password);
        console.log(req.body.id);
        res.send("save succesfull");
    });
});

app.listen(8080);



---------------USERS.JS CODE -----------

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

var user_schema = New Schema({
    email: String,
    username: String,
    password: String
});

var user = mongoose.model("user","user_schema");
mongoose.connect("mongodb://localhost/SoR");
module.exports.user = user;

New更改为new new是使用javascript中的构造函数创建对象的关键字。

Javascript无法识别您在代码中使用的New运算符,因此您会收到错误“ SyntaxError:意外的标识符”,因为New是意外的标识符。

MDN

当JavaScript引擎在解析代码时遇到不符合该语言语法的令牌或令牌顺序时,将引发SyntaxError。

var user_schema = New Schema({
    email: String,
    username: String,
    password: String
});

var user_schema = new Schema({
    email: String,
    username: String,
    password: String
});

暂无
暂无

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

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