node-mysql

How can I respond in XML using ExpressJS?

微笑、不失礼 提交于 2019-12-03 05:40:51
问题 I have a simple code that gives a JSON response for a specific route. Here's my current code: var express = require('express') , async = require('async') , http = require('http') , mysql = require('mysql'); var app = express(); var connection = mysql.createConnection({ host: 'localhost', user: '****', password: "****", database: 'restaurants' }); connection.connect(); // all environments app.set('port', process.env.PORT || 1235); app.use(express.static(__dirname + '/public/images')); app.get(

Best Way to Use OOP in Express REST API?

走远了吗. 提交于 2019-12-03 03:58:58
问题 I'm going all in and doing a project using only node. It's been a lot of fun, but sometimes I get a little lost in it and I want to try to gain understanding as I get confused so I build it correctly and don't get too overwhelmed. Anyway, here's the problem: I have REST API that's using Express and mysql. I set up mysql: app.js //Variables, move these to env var dbOptions = { host: config.db_config.host, user: config.db_config.user, password: config.db_config.password, port: config.db_config

Difference between using getConnection() and using pool directly in node.js with node-mysql module?

僤鯓⒐⒋嵵緔 提交于 2019-12-02 23:05:25
The documentation states that you can either use the pool directly with: pool.query(); or get a connection manually and then run a query: pool.getConnection(function(err, connection) { // Use the connection connection.query( 'SELECT something FROM sometable', function(err, rows) { // And done with the connection. connection.release(); // Don't use the connection here, it has been returned to the pool. }); }); The second option is a lot of code that has to be repeated every time you need to run a query. Is it safe to just use the pool directly? Does pool.query() release the connection back into

How can I respond in XML using ExpressJS?

只愿长相守 提交于 2019-12-02 19:00:31
I have a simple code that gives a JSON response for a specific route. Here's my current code: var express = require('express') , async = require('async') , http = require('http') , mysql = require('mysql'); var app = express(); var connection = mysql.createConnection({ host: 'localhost', user: '****', password: "****", database: 'restaurants' }); connection.connect(); // all environments app.set('port', process.env.PORT || 1235); app.use(express.static(__dirname + '/public/images')); app.get('/DescriptionSortedRating/',function(request,response){ var name_of_restaurants; async.series( [ // Get

Best Way to Use OOP in Express REST API?

巧了我就是萌 提交于 2019-12-02 18:17:06
I'm going all in and doing a project using only node. It's been a lot of fun, but sometimes I get a little lost in it and I want to try to gain understanding as I get confused so I build it correctly and don't get too overwhelmed. Anyway, here's the problem: I have REST API that's using Express and mysql. I set up mysql: app.js //Variables, move these to env var dbOptions = { host: config.db_config.host, user: config.db_config.user, password: config.db_config.password, port: config.db_config.port, database: config.db_config.database }; app.use(myConnection(mysql, dbOptions, 'single')); and

node-mysql pool experiences ETIMEDOUT

做~自己de王妃 提交于 2019-12-02 15:23:39
问题 I have a node-mysql pool configuration of var db_init={ host : 'ip_address_of_GCS_SQL', user : 'user_name_of_GCS_SQL', password : 'password here', database : 'db here', supportBigNumbers: true, connectionLimit:100 }; Pool was created using GLOBAL.db_foobar = mysql.createPool(db_init); I basically just left the connection on for a couple of hours and I saw this error reported by my connection.query Request (after getConnection of course): prodAPI-104 (out): { status: 'Error', prodAPI-104 (out)

Error: Handshake inactivity timeout in Node.js MYSQL module

我只是一个虾纸丫 提交于 2019-12-01 02:23:14
I'm using node-mysql and most of the queries. Working. some queries not working. I tried every version of Node (from 0.5...) until (5.6.0), I also tried (4.0) and (4.1), Nothing helps. I tried to change maually, and didn't work. I tried to change the sequence file to: this._idleTimeout = -1; and didn't help. I read the issues and GitHub, and nothing helped. I can try to fix it by myself, but I need more information. Where is the timeout, why? when? what is this type of message? Where is the timeout came from? MYSQL_ERROR { [Error: Handshake inactivity timeout] code: 'PROTOCOL_SEQUENCE_TIMEOUT'

Error: Handshake inactivity timeout in Node.js MYSQL module

倾然丶 夕夏残阳落幕 提交于 2019-11-30 21:57:01
问题 I'm using node-mysql and most of the queries. Working. some queries not working. I tried every version of Node (from 0.5...) until (5.6.0), I also tried (4.0) and (4.1), Nothing helps. I tried to change maually, and didn't work. I tried to change the sequence file to: this._idleTimeout = -1; and didn't help. I read the issues and GitHub, and nothing helped. I can try to fix it by myself, but I need more information. Where is the timeout, why? when? what is this type of message? Where is the

Return rows with nodejs and node-mysql

半城伤御伤魂 提交于 2019-11-30 21:30:27
I'm discovering Nodejs and the node-mysql module. I have a small problem. Every tutorial that I find explain how to do a select on the database but they never return the rows, they always log them, which is absolutely useless for my case. I have a app.js file : // Get continents app.get("/continents", function(request, result) { console.log("Continents : " + database.findAllContinents()); }); And a mysql.js file : exports.findAllContinents = function(connection) { var connection = getConnection(); connection.query('select id, code, name from Continent', function (err, rows, fields) { if (err)

Return rows with nodejs and node-mysql

笑着哭i 提交于 2019-11-30 17:11:19
问题 I'm discovering Nodejs and the node-mysql module. I have a small problem. Every tutorial that I find explain how to do a select on the database but they never return the rows, they always log them, which is absolutely useless for my case. I have a app.js file : // Get continents app.get("/continents", function(request, result) { console.log("Continents : " + database.findAllContinents()); }); And a mysql.js file : exports.findAllContinents = function(connection) { var connection =