Joshua Oliphant Joshua Oliphant - 4 months ago 13x
Javascript Question

javascript syntax error in node server

The problem is that when I start the server I get the error listed below. I'm pretty new to JavaScript, is this due to a difference in JavaScript or Nodejs versions? I also tried changing the var update to have

instead of
, but which gets the server to start, but then it won't update/delete data from our MongoDB. If it helps, the "Recipes" in
is a Mongoose schema.

Here is the function from the server.js:"/updaterecipe", function(req, res) {
var id = req.body.recipeID;
console.log("Updating recipe " + id);
var recipeName = req.body.recipeName;
var categoryID = req.body.categoryID;
var recipeInstructions = req.body.recipeInstructions;
var ingredientIDs = req.body.ingredientIDs;
var options = {new: false};
var update = {recipeName, categoryID, recipeInstructions, ingredientIDs};
Recipes.findOneAndUpdate({recipeID: id}, update, options, function(err) {
if (err)
console.log("Unable to update");

And the error:

var update = {recipeName, categoryID, recipeInstructions, ingredientIDs};

SyntaxError: Unexpected token ,
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.j


This is ES6 property shorthand:

var update = {recipeName, categoryID, recipeInstructions, ingredientIDs};


Simply upgrade to the latest version of node and you should be good to go.