SyntaxError:意外的令牌)

时间:2017-03-14 20:30:32

标签: node.js cassandra syntax-error

我正在使用Cassandra + Node.js来创建应用,但我收到此代码的错误:

C:\Users\userx\node-cassandra\app.js:44
app.post('/',new);
                ^
SyntaxError: Unexpected token )
at Module._compile (module.js:545:28)

这是我的代码

app.js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var helenus = require('helenus');

var index = require('./routes/index');
var users = require('./routes/users');

var app = express();

var pool = new helenus.ConnectionPool({
    hosts      : ['localhost:9160'],
    keyspace   : 'webinar',
    cqlVersion : '3.0.0',
    //user       : 'test',
    //password   : 'test1233',
    //timeout    : 3000
    //cqlVersion : '3.0.0' // specify this if you're using Cassandra 1.1 and       want to use CQL 3 
  });

  pool.connect(function(err){
if(err){
    throw(err);
}


// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.set('cassandra',pool);

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', routes.index);
app.post('/', new);
app.delete('/', delete);;

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app; 
});

index.js

exports.index = function(req, res, next){
req.app.get('cassandra').cql('SELECT * FROM users LIMIT 10',function(err, users){
if(err){
  return next(err);
}

res.render('index', { title: 'Users', users: users });
});
};

exports.new = function(req, res, next){
var insert = 'UPDATE users SET first_name=?, last_name=? WHERE email=?',
  params = [req.body.first_name, req.body.last_name, req.body.email];

req.app.get('cassandra').cql(insert,  params, function(err, users){
if(err){
  return next(err);
}

res.redirect('/');
});
};

exports.delete = function(req, res, next){
var remove = 'DELETE FROM users WHERE email=?',
  params = [req.body.email];

req.app.get('cassandra').cql(remove,  params, function(err, users){
if(err){
  return next(err);
}

res.redirect('/');
});
};

错误

SyntaxError:意外的令牌)

我只是想改变app.post('/',routes.new);

但它表明继承不能完成

请告诉我我的错误在哪里

1 个答案:

答案 0 :(得分:3)

new是ECMAScript中的reserved word。我不认为您可以将它用作成员名称,因为它被解释为创建一个新对象。