So, here's the code
let x = await this.storeFileName(fileName);
So, I've declared the storeFileName
function as async and I'm also returning a promise and everything till here is fine. But I'm getting an error that says :
SyntaxError: Unexpected token this
which is pointing to the 'this' followed by the await keyword
Btw I'm using an ES6 class and the this keyword refers to the object of that class.
It works without the await keyword but if I put await it throws an error.
What am I doing wrong? Everything seems correct. Can someone throw some light on me.
UPDATE :
These are the two functions.
async encodeName(x){
return new Promise((resolve,reject)=>{
const cipher = crypto.createCipher('aes192', this.PASSWORD);
let encrypted = cipher.update(x,'utf8', 'hex');
encrypted += cipher.final('hex');
if(encrypted.length>240){
let x = await this.storeFileName(encrypted);
resolve(`@Fn ${x}`);
}
resolve(encrypted);
});
}
async storeFileName(x){
return new Promise((resolve,reject)=>{
let doc = { encName: x };
filesDb = new db(`${this.mntpnt}/__CORE_rigel.pro/x100.db`);
filesDb.insert(doc,(err,newdoc)=>{
err?reject():resolve(newdoc._id);
});
});
}
Btw, I'm doing this on node.js
UPDATE 2 :
Here is the error message
A JavaScript error occurred in the main process
Uncaught Exception:
/home/teja/Documents/Rigel/components/diskEncryptor.js:32
let x = await this.storeFileName(encrypted);
^^^^
SyntaxError: Unexpected token this
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/teja/Documents/Rigel/index.js:4:23)