I always transform callback based APIs to use promises for convenience. That being said, people talk as if we were stuck in the stone age before promises but that's not true. A promise is basically a convenience structure to handle callbacks, and it is/was possible to write similar structures to handle callback APIs back in the days. It's just that most developers didn't bother because ¯\_(ツ)_/¯.
Regarding ...Sync functions, it depends. If I am writing a script to migrate a database, for instance, or doing some initialization when starting up a server, and the script/app can't do anything else until that operation is complete, using the ...Sync function makes the code slightly less convoluted and I prefer it. On the other hand, if the operation is used in an HTTP request handler, I want the app to be free to do other stuff while waiting for the operation, so I go for the asynchronous version.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I always transform callback based APIs to use promises for convenience. That being said, people talk as if we were stuck in the stone age before promises but that's not true. A promise is basically a convenience structure to handle callbacks, and it is/was possible to write similar structures to handle callback APIs back in the days. It's just that most developers didn't bother because ¯\_(ツ)_/¯.
Regarding
...Sync
functions, it depends. If I am writing a script to migrate a database, for instance, or doing some initialization when starting up a server, and the script/app can't do anything else until that operation is complete, using the...Sync
function makes the code slightly less convoluted and I prefer it. On the other hand, if the operation is used in an HTTP request handler, I want the app to be free to do other stuff while waiting for the operation, so I go for the asynchronous version.