簡體   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