简体   繁体   中英

callback function in sails.JS v1

I am new to sailsJS. I want to add record in collection named skills.

I have refered this document of sails js https://sailsjs.com/documentation/reference/waterline-orm/models/create

I have request as :

{
    "skillName": "tblPreffered PartneersTest",
    "active": "true"
}

my function is :

 FnCreate :  function(req,res){
    var Data = await Skills.create(req.body).exec().fetch();
    console.log('data  is :'+JSON.stringify(Data)); 
    res.send({
        status      : true,
        statusCode  : 200,
        message     : "New Skill added",
        responce    : Data,     
    })
  }

now when i run, it says error as :

var Data = await Skills.create(req.body).exec().fetch();
                         ^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier

can any one help me what should I do ?

You need you use async keyword :

FnCreate :  async function(req,res){
                  var Data = await Skills.create(req.body).fetch();
                  console.log('data  is :'+JSON.stringify(Data)); 
                  res.send({
                  status      : true,
                  statusCode  : 200,
                  message     : "New Skill added",
                  responce    : Data,     
            })
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM