Search code examples
javascriptnode.jswebstorm

WebStorm error: expression statement is not assignment or call


I'm using WebStorm and I'm getting an error that I can't understand. Node.js + MongoDB.

var mongoose = require('mongoose');

mongoose.Promise = global.Promise;
mongoose.connect(' mongodb://localhost:27017/TodoApp');

var Todo = mongoose.model('Todo', {
    text: {
        type: String
    },
    completed: {
        type: Boolean
    },
    completedAt: {
        type: Number
    }
});

var newTodo = new Todo({
    text: 'Cook dinner'
});

The problem is in this block:

newTodo.save().then((doc) => {
    console.log('Saved todo', doc);
}, (e) => {
    console.log('Unable to save todo')
})

P.S.: The code works fine.


Solution

  • You need to change JavaScript Language Version to ES6. Changing this setting should fix the issue:

    Settings to change Javscript version to ES6

    In some scenarios, you might need to restart your IDE for the changes to reflect properly.