Questions tagged [node-mysql]

A pure node.js JavaScript Client implementing the MySql protocol. This is about the node package `mysql`, not `node-mysql` which is much less popular.

699 questions
110
votes
5 answers

Preventing SQL injection in Node.js

Is it possible to prevent SQL injections in Node.js (preferably with a module) in the same way that PHP had Prepared Statements that protected against them. If so, how? If not, what are some examples that might bypass the code I've provided (see…
funseiki
  • 9,167
  • 9
  • 36
  • 59
44
votes
3 answers

Node.js MySQL Needing Persistent Connection

I need a persistent MySQL connection for my Node web app. The problem is that this happens about a few times a day: Error: Connection lost: The server closed the connection. at Protocol.end…
apscience
  • 7,033
  • 11
  • 55
  • 89
43
votes
2 answers

How can I respond in XML using ExpressJS?

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…
Devrath
  • 42,072
  • 54
  • 195
  • 297
41
votes
7 answers

Error: Handshake inactivity timeout in Node.js MYSQL module

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…
Aminadav Glickshtein
  • 23,232
  • 12
  • 77
  • 117
40
votes
9 answers

Use promise to process MySQL return value in node.js

I have a python background and is currently migrating to node.js. I have problem adjusting to node.js due to its asynchronous nature. For example, I am trying to return a value from a MySQL function. function getLastRecord(name) { var…
guagay_wk
  • 26,337
  • 54
  • 186
  • 295
40
votes
6 answers

Node MySQL escape LIKE statement

How do escape a MySQL LIKE statement in node-mysql? Something along the lines of "SELECT * FROM card WHERE name LIKE '%" + connection.escape(req.body.search) + "%'" Results in 'SELECT * FROM card WHERE name LIKE \'%\'hello\'%\'' Which is a syntax…
dtsn
  • 1,077
  • 1
  • 10
  • 17
28
votes
5 answers

JavaScript classes with getter and setter cause RangeError: Maximum call stack size exceeded

I am currently experimenting with ECMA6 classes. My current class looks like the following class Player { constructor(id) { this.id = id; this.cash = 350; } get cash() { return this.cash; } set cash(value) { // line 19 …
Jannis Lehmann
  • 1,428
  • 3
  • 17
  • 31
28
votes
2 answers

How to properly pass mysql connection to routes with express.js

I am trying to figure out the best way to pass a mysql connection (using node-mysql) between my routes for express.js. I am dynamically adding each route (using a for each file loop in routes), meaning I can't just pass in the connection to routes…
anonymousfox
  • 769
  • 2
  • 9
  • 19
25
votes
1 answer

node.js-MySQL COUNT the number of records

I have following code. var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', user : 'root', password : '', database : 'test' }); connection.connect(); var userdata = '24'; var sql = 'SELECT…
Shekhar
  • 910
  • 1
  • 13
  • 23
23
votes
4 answers

MySQL giving "read ECONNRESET" error after idle time on node.js server

I'm running a Node server connecting to MySQL via the node-mysql module. Connecting to and querying MySQL works great initially without any errors, however, the first query after leaving the Node server idle for a couple hours results in an error.…
Brent Traut
  • 5,614
  • 6
  • 29
  • 54
23
votes
3 answers

INSERT INTO fails with node-mysql

I am trying to insert some data with node.js. I have written the following code and installed MySQL support via npm, but I failed to INSERT INTO the table. Here is my code: var mysql = require('mysql'); function BD() { var connection =…
rokirakan78
  • 251
  • 1
  • 2
  • 9
22
votes
7 answers

Node.js mysql transaction

Can anyone provide an example of how I could achieve MySQL transactions in Node.js. I am trying to get my head around using the node-mysql driver and node-mysql-queue. As far are I can tell, using node-mysql-queue greatly reduces the asynchronous…
Adam S
  • 251
  • 1
  • 2
  • 4
20
votes
1 answer

How does connectionLimit work in node mysql?

I quite don't understand how connectionLimit in mysql module works. I have created a connectionPool in following way: var connPool = mysql.createPool({ host: config.get('database.host'), user: config.get('database.user'), …
Vikas
  • 720
  • 1
  • 9
  • 30
20
votes
2 answers

What is the difference between single ( ? ) and double question mark ( ?? ) in node-mysql?

Am sure this is fairly obvious, to me it would make more sense if the second double question mark in the example was a single one. From their docs: Alternatively, you can use ?? characters as placeholders for identifiers you would like to have…
Sean McClory
  • 4,195
  • 3
  • 32
  • 35
18
votes
1 answer

node.js mysql pool beginTransaction & connection

I've been wondering if beginTransaction in node.js mysql uses multiple connections (if I have multiple queries inside the transaction) in a pool or is it only using a single connection until it is committed?
Edwin Bermejo
  • 432
  • 3
  • 5
  • 17
1
2 3
46 47