your code looks to me a little spagetthi code with that “async main”. try first clearing your code. It may solve itself when you do so.
- you are using “async” main function. you need to wait for it to complete its run. otherwise, the program will not behave as you would expect. try “
await main()”
- your client is not global (let and const, not var), so this may cause connection problems for that endpoint. try setting your client as a singleton outside.
- move the definition for that endpoint outside along with above step.
- you start server too early before you before you set up all endpoints. this may cause problems, especially when using async functions. move server start up line to the end of file.
also there maybe more than one async approach used in the chain, but “await” may not wait at each node. also try to split “find” and “toArray” into 2 lines.
check these steps, then tell use more if they won’t solve your problem.
1 Like