Creating an API using nodejs
const_=require('lodash');
const func=require('./func');
conditions = [item1, item2,...];
const data={};
constmain=async()=>{
for (leti=0;i<items.length;i++) {
_.assign(data,{
[items[i]]: wait func.getData(items[i])
});
}
keywords.forEach((item,index,self)=>{
_.assign(data,{
item : wait func.getData(item)
});
});
console.log(data);
};
main();
When turning the loop for an array of items, such as the one above, the following error occurs only for each item:
[item]:wait func.getData(item,30)
^^^^
SyntaxError: Unexpected identifier
What is the cause of this?
func defines a group of functions in a separate file and exports async function.
It seems that async
is required for forEach callback.
keywords.forEach(async(item, index, self)=>{}
© 2024 OneMinuteCode. All rights reserved.