通过cmd运行此代码时出现此错误。错误告诉它在行中没有。 7但无法找到。
var express = require('express'),
filter = express(),
server = require('http').createServer(filter),
io = require('socket.io').listen(server),
mongoose = require('mongoose'),
server.listen(1149, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1149/');
mongoose.connect('mongodb://localhost/chat', function(err){
if(err){
console.log(err);
} else{
console.log('Connected to mongodb!');
}
});
var filter_CheckBoxSchema = mongoose.Schema({
category : { type: Boolean, default: false },
created: {type: Date, default: Date.now}
});
我收到错误:
C:\node\people discovery app\filter.js:7
server.listen(1149, '127.0.0.1');
^
SyntaxError: Unexpected token .
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
答案 0 :(得分:5)
从第一行开始的变量声明永远不会完成,因此声明:
server.listen(1149, '127.0.0.1');
被视为变量声明,而在此处它不是有效声明。
要解决此问题,您可以使用var
从第一行开始填写;
语句,例如:
var express = require('express'),
filter = express(),
server = require('http').createServer(filter),
io = require('socket.io').listen(server),
mongoose = require('mongoose'); // <-- Notice the ';' here
server.listen(1149, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1149/');
...