How can I use mysql synchronously in node.js ? I want to execute query and render properly rendered form with datas from database, like:
userData = db.query "SELECT * FROM users WHERE id=1"
form.bind(userData)
res.render 'user/edit', {'form' : form}
By the title I assume that you mean in a synchronous way. The answer is you can't. This is because NodeJS is single-threaded and since I/O (i.e. communication with database) is handled in a separate thread (which is used internally by NodeJS, it is not available for programmers) the result of I/O is pushed to the top of the event loop. But NodeJS can't jump to another event in the event loop without leaving current event.
Whether you like it or not you have to stick with asynchronous patterns.