Android Man
Android Man

Reputation: 319

Getting unexpected token when running

While running this code through cmd i am getting this error. The error tells that its in line no. 7 but could't find.

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}
});

I am getting an error:

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

Upvotes: 0

Views: 10748

Answers (1)

ebo
ebo

Reputation: 2747

The variable declaration started on the first line is never finished, thus the statement:

server.listen(1149, '127.0.0.1');

is seen as a variable declaration, while it is not a valid statement here.

To fix this you can finish the var statement starting on the first line with a ;, e.g.:

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/');
...

Upvotes: 5

Related Questions