node-mysql where does connection.end() go

后端 未结 2 1969
悲哀的现实
悲哀的现实 2021-02-12 13:11

I am really confused with using connection.end() in node-mysql.

I don\'t fully understand where it goes, at the moment i place it after a query but then if i create a ne

2条回答
  •  失恋的感觉
    2021-02-12 13:27

    Per the documentation:

    Closing the connection is done using end() which makes sure all remaining queries are executed before sending a quit packet to the mysql server.

    connection.end() is then supposed to be called only when you stop sending queries to MySQL, i.e. when your application is stopping. You shouldn't create/end connections all the time: just use the same connection for all your queries (or use a connection pool to be more efficient).

提交回复
热议问题