2017-02-08 6 views
0

私はnodejsでこのコードを実行すると、それは私に、このエラーを返します:「にSyntaxError:予期しない識別子」この行の ...スキーママングース予想外の識別子

var user_schema = New 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; 
+0

は、代わりに '' New'のnew'を試してみてください – Brian

答えて

1

変更にNewnewには(私の英語のため申し訳ありませんが、私はスペイン語を話します)。 newは、javascriptのコンストラクタ関数を使用してオブジェクトを作成するためのキーワードです。

JavaScriptで、コードで使用したNew演算子が認識されないため、「SyntaxError:Unexpected Identifier」というエラーが表示されます。Newは予期しない識別子です。

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

A SyntaxError is thrown when the JavaScript engine encounters tokens or token order that does not conform to the syntax of the language when parsing code.

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

から

関連する問題