Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

node.js - Async/Await is not working with node 4.x. Can i have the alternate?

Getting below error when i try to use async/await with NodeJs 4.x. Any issue with the below sample code or should i use alternate ?

async function main () { ^^^^^^^^

SyntaxError: Unexpected token function

Code Samples:

(async function () {

        const intgetIDvalue = await fntest(getID);

     }

 })();

 async function fntest (getID) {
   return await knex
     .select('column1')
     .from('tablename')
     .where('ID',getID)
 }
question from:https://stackoverflow.com/questions/65878103/missing-after-argument-list-in-centos-7-vps-server-running-normal-in-my-windo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try installing asyncawait. It should work for older node versions. Other alternatives are using a callback or promises.

you'll have to require it

  1. npm install asyncawait

  2. require modules.

    var async = require('asyncawait/async');

    var await = require('asyncawait/await');

  3. perform operations.

    (async function () { const intgetIDvalue = await fntest(getID); })();


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...